summaryrefslogtreecommitdiff
path: root/dhall/src
diff options
context:
space:
mode:
Diffstat (limited to 'dhall/src')
-rw-r--r--dhall/src/semantics/parse.rs4
-rw-r--r--dhall/src/semantics/resolve/resolve.rs16
2 files changed, 15 insertions, 5 deletions
diff --git a/dhall/src/semantics/parse.rs b/dhall/src/semantics/parse.rs
index 2326471..82396e0 100644
--- a/dhall/src/semantics/parse.rs
+++ b/dhall/src/semantics/parse.rs
@@ -4,7 +4,7 @@ use std::path::Path;
use url::Url;
use crate::error::Error;
-use crate::semantics::resolve::ImportLocation;
+use crate::semantics::resolve::{download_http_text, ImportLocation};
use crate::syntax::binary;
use crate::syntax::parse_expr;
use crate::Parsed;
@@ -17,7 +17,7 @@ pub fn parse_file(f: &Path) -> Result<Parsed, Error> {
}
pub fn parse_remote(url: Url) -> Result<Parsed, Error> {
- let body = reqwest::blocking::get(url.clone()).unwrap().text().unwrap();
+ let body = download_http_text(url.clone())?;
let expr = parse_expr(&body)?;
let root = ImportLocation::Remote(url);
Ok(Parsed(expr, root))
diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs
index 3b72b9e..fb770db 100644
--- a/dhall/src/semantics/resolve/resolve.rs
+++ b/dhall/src/semantics/resolve/resolve.rs
@@ -159,9 +159,7 @@ impl ImportLocation {
fn fetch_text(self) -> Result<String, Error> {
Ok(match self {
ImportLocation::Local(path) => std::fs::read_to_string(&path)?,
- ImportLocation::Remote(url) => {
- reqwest::blocking::get(url).unwrap().text().unwrap()
- }
+ ImportLocation::Remote(url) => download_http_text(url)?,
ImportLocation::Env(var_name) => match env::var(var_name) {
Ok(val) => val,
Err(_) => return Err(ImportError::MissingEnvVar.into()),
@@ -197,6 +195,18 @@ fn mkexpr(kind: UnspannedExpr) -> Expr {
Expr::new(kind, Span::Artificial)
}
+// TODO: error handling
+#[cfg(not(target_arch = "wasm32"))]
+pub(crate) fn download_http_text(url: Url) -> Result<String, Error> {
+ Ok(reqwest::blocking::get(url).unwrap().text().unwrap())
+}
+#[cfg(target_arch = "wasm32")]
+pub(crate) fn download_http_text(url: Url) -> Result<String, Error> {
+ blocking::block_on(async {
+ Ok(reqwest::get(url).await.unwrap().text().await.unwrap())
+ })
+}
+
fn make_aslocation_uniontype() -> Expr {
let text_type = mkexpr(ExprKind::Builtin(Builtin::Text));
let mut union = BTreeMap::default();