Skip to content

Commit

Permalink
Make sure error outputs are what we expect (#114)
Browse files Browse the repository at this point in the history
I've added a `--verify` mode to `tutorial_generator`: expected error
outputs are now committed to `.git` and we verify, in CI, that the
auto-generated ones match what we expect.

This ensures that we never see again a regression like the one we fixed
in #113: the step was failing as expected but with a completely
different error from the one we wanted.
  • Loading branch information
LukeMathWalker authored Dec 10, 2023
1 parent 2680be5 commit c05c3f0
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
- name: Generate quickstart tutorial
run: |
cd doc_examples/quickstart
tutorial_generator
tutorial_generator --verify
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
Expand Down
1 change: 1 addition & 0 deletions doc_examples/quickstart/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
!*.snap
!*.patch
!tutorial.yml
23 changes: 23 additions & 0 deletions doc_examples/quickstart/05-error.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ERROR:
× I can't invoke your request handler, `demo::routes::greet::greet`, because it needs an
instance of `demo::user_agent::UserAgent` as input, but I can't find a constructor for that
type.
│ ╭─[demo/src/blueprint.rs:14:1]
14bp.route(GET, "/api/ping", f!(crate::routes::status::ping));
15bp.route(GET, "/api/greet/:name", f!(crate::routes::greet::greet));
│ · ───────────────┬───────────────
│ · ╰── The request handler was registered here
16bp
│ ╰────
│ ╭─[demo/src/routes/greet.rs:13:1]
13
14pub fn greet(params: RouteParams<GreetParams>, user_agent: UserAgent) -> Response {
│ · ────┬────
│ · ╰── I don't know how to construct an instance of this input parameter
15if let UserAgent::Unknown = user_agent {
│ ╰────
│ help: Register a constructor for `demo::user_agent::UserAgent`

Error: `pavex_cli` exited with a non-zero status code: 1
error: Failed to run `bp`, the code generator for package `demo_server_sdk`
16 changes: 16 additions & 0 deletions doc_examples/quickstart/07-error.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ERROR:
× You registered a constructor that returns a `Result`, but you did not register an error
handler for it. If I don't have an error handler, I don't know what to do with the error when
the constructor fails!
│ ╭─[demo/src/blueprint.rs:12:1]
12bp.constructor(
13f!(crate::user_agent::UserAgent::extract),
│ · ────────────────────┬────────────────────
│ · ╰── The fallible constructor was registered here
14Lifecycle::RequestScoped,
│ ╰────
help: Add an error handler via `.error_handler`

Error: `pavex_cli` exited with a non-zero status code: 1
error: Failed to run `bp`, the code generator for package `demo_server_sdk`
8 changes: 4 additions & 4 deletions doc_examples/quickstart/tutorial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ steps:
- patch: "05-bis.patch"
commands:
- command: "cargo px c -q"
outcome: "failure"
save_at: "05-error.txt"
expected_outcome: "failure"
expected_output_at: "05-error.snap"
- patch: "06.patch"
- patch: "07.patch"
commands:
- command: "cargo px c -q"
outcome: "failure"
save_at: "07-error.txt"
expected_outcome: "failure"
expected_output_at: "07-error.snap"
- patch: "08.patch"
- patch: "09.patch"
- patch: "10.patch"
105 changes: 105 additions & 0 deletions doc_examples/tutorial_generator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions doc_examples/tutorial_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ serde_yaml = "0.9.27"
serde_path_to_error = "0.1"
serde = { version = "1", features = ["derive"] }
run_script = "0.10"
similar = { version = "2.3", features = ["inline"] }
console = "0.15.1"
Loading

0 comments on commit c05c3f0

Please sign in to comment.