Skip to content

Commit

Permalink
Catch permissions errors in mdbook-aquascope
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Aug 30, 2023
1 parent 9a1d9c3 commit 62cb9c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ script = """
cargo run --bin export-ts
cargo test -p aquascope -p mdbook-aquascope --lib export_bindings
mkdir -p frontend/packages/aquascope-editor/src/bindings
cp crates/**/bindings/* frontend/packages/aquascope-editor/src/bindings"""
cp crates/**/bindings/* frontend/packages/aquascope-editor/src/bindings
"""

[tasks.install-mdbook]
dependencies = ["init-bindings"]
Expand Down
13 changes: 12 additions & 1 deletion crates/mdbook-aquascope/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,25 @@ impl AquascopePreprocessor {

let response = String::from_utf8(output.stdout)?;
let response_json: serde_json::Value = serde_json::from_str(&response)?;
if response_json.get("Err").is_some() {
let is_err = match (response_json.as_object(), response_json.as_array()) {
(Some(obj), _) => obj.get("Err").is_some(),
(_, Some(arr)) => arr.iter().any(|obj| obj.get("Err").is_some()),
_ => false,
};
if is_err {
let stderr = String::from_utf8(output.stderr)?;
bail!(
"Aquascope failed for program:\n{}\nwith error:\n{stderr}",
block.code,
)
}

if let Some("BuildError") =
response_json.get("type").and_then(|ty| ty.as_str())
{
bail!("Aquascope failed for program:\n{}", block.code)
}

responses.insert(operation, response_json);
}

Expand Down

0 comments on commit 62cb9c4

Please sign in to comment.