From 138507d41fc48cd66084be158dfebc971103b0d9 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Tue, 21 Jan 2025 20:40:26 -0500 Subject: [PATCH] feat: improve parse error slightly --- src/registry.rs | 4 ++-- tests/snapshot.rs | 11 +++++++++++ tests/snapshots/snapshot__invalid_inputs.snap | 17 +++++++++++++++++ tests/test-data/invalid/invalid-workflow.yml | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/snapshots/snapshot__invalid_inputs.snap create mode 100644 tests/test-data/invalid/invalid-workflow.yml diff --git a/src/registry.rs b/src/registry.rs index d0eda403..833a8cdc 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -159,8 +159,8 @@ impl InputRegistry { Err(we) => match Action::from_file(path, prefix) { Ok(action) => self.register_input(action.into()), Err(ae) => Err(anyhow!("failed to register input as workflow or action")) - .with_context(|| we) - .with_context(|| ae), + .with_context(|| format!("{ae:?}")) + .with_context(|| format!("{we:?}")), }, } } diff --git a/tests/snapshot.rs b/tests/snapshot.rs index 632c29df..d7853ec0 100644 --- a/tests/snapshot.rs +++ b/tests/snapshot.rs @@ -127,6 +127,17 @@ fn test_conflicting_online_options() -> Result<()> { Ok(()) } +#[test] +fn test_invalid_inputs() -> Result<()> { + insta::assert_snapshot!(zizmor() + .output(OutputMode::Stderr) + .offline(true) + .workflow(workflow_under_test("invalid/invalid-workflow.yml")) + .run()?); + + Ok(()) +} + #[test] fn artipacked() -> Result<()> { insta::assert_snapshot!(zizmor() diff --git a/tests/snapshots/snapshot__invalid_inputs.snap b/tests/snapshots/snapshot__invalid_inputs.snap new file mode 100644 index 00000000..6d94fe12 --- /dev/null +++ b/tests/snapshots/snapshot__invalid_inputs.snap @@ -0,0 +1,17 @@ +--- +source: tests/snapshot.rs +expression: "zizmor().output(OutputMode::Stderr).offline(true).workflow(workflow_under_test(\"invalid/invalid-workflow.yml\")).run()?" +snapshot_kind: text +--- +failed to register input: @@INPUT@@ + +Caused by: + 0: invalid GitHub Actions workflow: file://@@INPUT@@ + + Caused by: + jobs: data did not match any variant of untagged enum Job at line 10 column 3 + 1: invalid GitHub Actions definition: file://@@INPUT@@ + + Caused by: + missing field `runs` + 2: failed to register input as workflow or action diff --git a/tests/test-data/invalid/invalid-workflow.yml b/tests/test-data/invalid/invalid-workflow.yml new file mode 100644 index 00000000..0a154ff7 --- /dev/null +++ b/tests/test-data/invalid/invalid-workflow.yml @@ -0,0 +1,14 @@ +name: "invalid-workflow" + +on: + repository_dispatch: + +permissions: + contents: read + +jobs: + invalid: + name: "invalid" + + steps: + - run: echo hello