Skip to content

Commit

Permalink
chore: display jq compilation errors (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
8e8b2c authored Sep 16, 2024
1 parent 35a67b6 commit 4c41a1b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
7 changes: 5 additions & 2 deletions crates/jaq_wrapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ pub fn compile_filter(program_str: &str) -> ExternResult<Filter> {

if !errs.is_empty() {
return Err(wasm_error!(format!(
"jq program compilation failed with {} error(s)",
errs.len()
"jq program compilation failed with error(s):\n\n{}",
errs.into_iter()
.map(|err| err.to_string())
.collect::<Vec<String>>()
.join("\n\n")
)));
}
let Some(main) = maybe_main else {
Expand Down
7 changes: 5 additions & 2 deletions crates/username_registry_validation/src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ pub fn validate_create_recipe(
input_var_names,
program,
} => {
if compile_filter(&program).is_err() {
return Ok(ValidateCallbackResult::Invalid("Invalid jq program".into()));
if let Err(err) = compile_filter(&program) {
return Ok(ValidateCallbackResult::Invalid(format!(
"Invalid jq program: {}",
err
)));
}
match input_var_names {
JqInstructionArgumentNames::List { var_names } => var_names,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { expect, test } from "vitest";
import { runScenario } from "@holochain/tryorama";

import { setupPlayer } from "../utils/setup-happ.js";
import { fakeAgentPubKey } from "@holochain/client";

test("Cannot create recipe with bad jq program", async () => {
await runScenario(async (scenario) => {
const [_, authorityCoordinators] = await setupPlayer(scenario);

await expect(
authorityCoordinators.usernameRegistry.createRecipe({
trusted_authors: [await fakeAgentPubKey(0)],
arguments: [],
instructions: [
[
"$return",
{
type: "Jq",
input_var_names: {
type: "List",
var_names: [],
},
program: "bad syntax",
},
],
],
})
).rejects.toSatisfy((err: Error) =>
err.message.includes("jq program compilation failed with error(s):")
);
});
});

0 comments on commit 4c41a1b

Please sign in to comment.