Skip to content

Commit

Permalink
Fix construction of diagnostic spans for pre-processing middlewares. (L…
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeMathWalker authored Mar 24, 2024
1 parent 9569b05 commit b4747c8
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
│ This request handler doesn't: it returns the unit type, `()`. I can't
│ convert `()` into an HTTP response.
│
│ ╭─[src/lib.rs:68:1]
│ 68 │ bp.route(GET, "/home", f!(crate::handler));
│ 69 │ bp.route(GET, "/unit", f!(crate::unit_handler));
│ ╭─[src/lib.rs:79:1]
│ 79 │ bp.route(GET, "/home", f!(crate::handler));
│ 80 │ bp.route(GET, "/unit", f!(crate::unit_handler));
│ ·  ───────────┬───────────
│ · The request handler was registered here
│ 70 │ bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
│ 81 │ bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
│ ╰────

ERROR:
Expand All @@ -18,37 +18,37 @@
│ This request handler doesn't: it returns the unit type, `()`, when
│ successful. I can't convert `()` into an HTTP response.
│
│ ╭─[src/lib.rs:69:1]
│ 69 │ bp.route(GET, "/unit", f!(crate::unit_handler));
│ 70 │ bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
│ ╭─[src/lib.rs:80:1]
│ 80 │ bp.route(GET, "/unit", f!(crate::unit_handler));
│ 81 │ bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
│ ·  ────────────────┬───────────────
│ · The request handler was registered here ──╯
│ 71 │ .error_handler(f!(crate::error_handler));
│ 82 │ .error_handler(f!(crate::error_handler));
│ ╰────

ERROR:
× All constructors must return *something*.
│ This constructor doesn't: it returns the unit type, `()`.
│
│ ╭─[src/lib.rs:53:1]
│ 53 │ let mut bp = Blueprint::new();
│ 54 │ bp.constructor(f!(crate::constructor), Lifecycle::Singleton);
│ ╭─[src/lib.rs:61:1]
│ 61 │ let mut bp = Blueprint::new();
│ 62 │ bp.constructor(f!(crate::constructor), Lifecycle::Singleton);
│ ·  ───────────┬──────────
│ · ╰── The constructor was registered here
│ 55 │ bp.constructor(
│ 63 │ bp.request_scoped(f!(crate::fallible_unit_constructor));
│ ╰────

ERROR:
× All fallible constructors must return *something* when successful.
│ This fallible constructor doesn't: it returns the unit type when
│ successful, `Ok(())`.
│
│ ╭─[src/lib.rs:55:1]
│ 55 │ bp.constructor(
│ 56 │ f!(crate::fallible_constructor_building_unit),
│ ·  ──────────────────────┬──────────────────────
│ · ╰── The constructor was registered here
│ 57 │ Lifecycle::RequestScoped,
│ ╭─[src/lib.rs:62:1]
│ 62 │ bp.constructor(f!(crate::constructor), Lifecycle::Singleton);
│ 63 │ bp.request_scoped(f!(crate::fallible_unit_constructor));
│ ·  ───────────────────────────────────
│ · The constructor was registered here ──╯
│ 64 │ bp.request_scoped(f!(crate::fallible_constructor))
│ ╰────

ERROR:
Expand All @@ -57,12 +57,12 @@
│ This middleware doesn't: it returns the unit type, `()`. I can't convert
│ `()` into an HTTP response.
│
│ ╭─[src/lib.rs:61:1]
│ 61 │
│ 62 │ bp.wrap(f!(crate::unit_wrapping_middleware));
│ ·  ─────────────────┬─────────────────
│ · The wrapping middleware was registered here
│ 63 │ bp.wrap(f!(crate::fallible_wrapping_middleware))
│ ╭─[src/lib.rs:70:1]
│ 70 │
│ 71 │ bp.wrap(f!(crate::unit_wrapping));
│ ·  ───────────────────────
│ · ╰── The wrapping middleware was registered here
│ 72 │ bp.wrap(f!(crate::fallible_unit_wrapping))
│ ╰────

ERROR:
Expand All @@ -71,12 +71,37 @@
│ This middleware doesn't: it returns the unit type, `()`, when successful.
│ I can't convert `()` into an HTTP response.
│
│ ╭─[src/lib.rs:62:1]
│ 62 │ bp.wrap(f!(crate::unit_wrapping_middleware));
│ 63 │ bp.wrap(f!(crate::fallible_wrapping_middleware))
│ ·  ───────────────────┬───────────────────
│ ╭─[src/lib.rs:71:1]
│ 71 │ bp.wrap(f!(crate::unit_wrapping));
│ 72 │ bp.wrap(f!(crate::fallible_unit_wrapping))
│ ·  ────────────────────────────────
│ · The wrapping middleware was registered here
│ 64 │ .error_handler(f!(crate::error_handler));
│ 73 │ .error_handler(f!(crate::error_handler));
│ ╰────

ERROR:
× Pre-processing middlewares must return `pavex::middleware::Processing`.
│ This middleware doesn't: it returns the unit type, `()`.
│
│ ╭─[src/lib.rs:66:1]
│ 66 │
│ 67 │ bp.pre_process(f!(crate::unit_pre));
│ ·  ─────────┬─────────
│ · The pre-processing middleware was registered here
│ 68 │ bp.pre_process(f!(crate::fallible_unit_pre))
│ ╰────

ERROR:
× Pre-processing middlewares must return `pavex::middleware::Processing`
│ when successful.
│ This middleware doesn't: it returns the unit type, `()`, when successful.
│
│ ╭─[src/lib.rs:67:1]
│ 67 │ bp.pre_process(f!(crate::unit_pre));
│ 68 │ bp.pre_process(f!(crate::fallible_unit_pre))
│ ·  ──────────────┬─────────────
│ · The pre-processing middleware was registered here
│ 69 │ .error_handler(f!(crate::error_handler));
│ ╰────

ERROR:
Expand All @@ -85,12 +110,12 @@
│ This middleware doesn't: it returns the unit type, `()`. I can't convert
│ `()` into an HTTP response.
│
│ ╭─[src/lib.rs:64:1]
│ 64 │ .error_handler(f!(crate::error_handler));
│ 65 │ bp.post_process(f!(crate::unit_pp_middleware));
│ ·  ──────────────┬──────────────
│ ╭─[src/lib.rs:74:1]
│ 74 │
│ 75 │ bp.post_process(f!(crate::unit_post));
│ ·  ───────────────────
│ · The post-processing middleware was registered here
│ 66 │ bp.post_process(f!(crate::fallible_pp_middleware))
│ 76 │ bp.post_process(f!(crate::fallible_unit_post))
│ ╰────

ERROR:
Expand All @@ -99,12 +124,12 @@
│ This middleware doesn't: it returns the unit type, `()`, when successful.
│ I can't convert `()` into an HTTP response.
│
│ ╭─[src/lib.rs:65:1]
│ 65 │ bp.post_process(f!(crate::unit_pp_middleware));
│ 66 │ bp.post_process(f!(crate::fallible_pp_middleware))
│ ·  ────────────────┬────────────────
│ ╭─[src/lib.rs:75:1]
│ 75 │ bp.post_process(f!(crate::unit_post));
│ 76 │ bp.post_process(f!(crate::fallible_unit_post))
│ ·  ────────────────────────────
│ · The post-processing middleware was registered here
│ 67 │ .error_handler(f!(crate::error_handler));
│ 77 │ .error_handler(f!(crate::error_handler));
│ ╰────

ERROR:
Expand All @@ -113,12 +138,12 @@
│ `app::error_handler` doesn't, it returns the unit type, `()`. I can't
│ convert `()` into an HTTP response!
│
│ ╭─[src/lib.rs:59:1]
│ 59 │ bp.constructor(f!(crate::fallible_constructor), Lifecycle::RequestScoped)
│ 60 │ .error_handler(f!(crate::error_handler));
│ ╭─[src/lib.rs:64:1]
│ 64 │ bp.request_scoped(f!(crate::fallible_constructor))
│ 65 │ .error_handler(f!(crate::error_handler));
│ ·  ────────────┬───────────
│ · The error handler was registered here
│ 61 │
│ 66 │
│ ╰────

ERROR:
Expand All @@ -127,12 +152,12 @@
│ `app::error_handler` doesn't, it returns the unit type, `()`. I can't
│ convert `()` into an HTTP response!
│
│ ╭─[src/lib.rs:63:1]
│ 63 │ bp.wrap(f!(crate::fallible_wrapping_middleware))
│ 64 │ .error_handler(f!(crate::error_handler));
│ ╭─[src/lib.rs:68:1]
│ 68 │ bp.pre_process(f!(crate::fallible_unit_pre))
│ 69 │ .error_handler(f!(crate::error_handler));
│ ·  ────────────┬───────────
│ · The error handler was registered here
│ 65 │ bp.post_process(f!(crate::unit_pp_middleware));
│ 70 │
│ ╰────

ERROR:
Expand All @@ -141,12 +166,12 @@
│ `app::error_handler` doesn't, it returns the unit type, `()`. I can't
│ convert `()` into an HTTP response!
│
│ ╭─[src/lib.rs:66:1]
│ 66 │ bp.post_process(f!(crate::fallible_pp_middleware))
│ 67 │ .error_handler(f!(crate::error_handler));
│ ╭─[src/lib.rs:72:1]
│ 72 │ bp.wrap(f!(crate::fallible_unit_wrapping))
│ 73 │ .error_handler(f!(crate::error_handler));
│ ·  ────────────┬───────────
│ · The error handler was registered here
│ 68 │ bp.route(GET, "/home", f!(crate::handler));
│ 74 │
│ ╰────

ERROR:
Expand All @@ -155,10 +180,24 @@
│ `app::error_handler` doesn't, it returns the unit type, `()`. I can't
│ convert `()` into an HTTP response!
│
│ ╭─[src/lib.rs:70:1]
│ 70 │ bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
│ 71 │ .error_handler(f!(crate::error_handler));
│ ╭─[src/lib.rs:76:1]
│ 76 │ bp.post_process(f!(crate::fallible_unit_post))
│ 77 │ .error_handler(f!(crate::error_handler));
│ ·  ────────────┬───────────
│ · The error handler was registered here
│ 78 │
│ ╰────

ERROR:
× All error handlers must return a type that implements
│ `pavex::response::IntoResponse`.
│ `app::error_handler` doesn't, it returns the unit type, `()`. I can't
│ convert `()` into an HTTP response!
│
│ ╭─[src/lib.rs:81:1]
│ 81 │ bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
│ 82 │ .error_handler(f!(crate::error_handler));
│ ·  ────────────┬───────────
│ · The error handler was registered here
│ 72 │ bp
│ 83 │ bp
│ ╰────
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn constructor() {
#[derive(Debug)]
pub struct Error;

pub fn fallible_constructor_building_unit() -> Result<(), Error> {
pub fn fallible_unit_constructor() -> Result<(), Error> {
todo!()
}

Expand All @@ -25,19 +25,27 @@ pub fn handler() -> Response {
todo!()
}

pub fn unit_wrapping_middleware() {
pub fn unit_wrapping() {
todo!()
}

pub fn fallible_wrapping_middleware() -> Result<(), Error> {
pub fn fallible_unit_wrapping() -> Result<(), Error> {
todo!()
}

pub fn unit_pp_middleware(_response: Response) {
pub fn unit_pre() {
todo!()
}

pub fn fallible_pp_middleware(_response: Response) -> Result<(), Error> {
pub fn unit_post(_response: Response) {
todo!()
}

pub fn fallible_unit_pre() -> Result<(), Error> {
todo!()
}

pub fn fallible_unit_post(_response: Response) -> Result<(), Error> {
todo!()
}

Expand All @@ -52,19 +60,22 @@ pub fn fallible_unit_handler() -> Result<(), Error> {
pub fn blueprint() -> Blueprint {
let mut bp = Blueprint::new();
bp.constructor(f!(crate::constructor), Lifecycle::Singleton);
bp.constructor(
f!(crate::fallible_constructor_building_unit),
Lifecycle::RequestScoped,
);
bp.constructor(f!(crate::fallible_constructor), Lifecycle::RequestScoped)
bp.request_scoped(f!(crate::fallible_unit_constructor));
bp.request_scoped(f!(crate::fallible_constructor))
.error_handler(f!(crate::error_handler));

bp.wrap(f!(crate::unit_wrapping_middleware));
bp.wrap(f!(crate::fallible_wrapping_middleware))
bp.pre_process(f!(crate::unit_pre));
bp.pre_process(f!(crate::fallible_unit_pre))
.error_handler(f!(crate::error_handler));
bp.post_process(f!(crate::unit_pp_middleware));
bp.post_process(f!(crate::fallible_pp_middleware))

bp.wrap(f!(crate::unit_wrapping));
bp.wrap(f!(crate::fallible_unit_wrapping))
.error_handler(f!(crate::error_handler));

bp.post_process(f!(crate::unit_post));
bp.post_process(f!(crate::fallible_unit_post))
.error_handler(f!(crate::error_handler));

bp.route(GET, "/home", f!(crate::handler));
bp.route(GET, "/unit", f!(crate::unit_handler));
bp.route(GET, "/fallible_unit", f!(crate::fallible_unit_handler))
Expand Down
Loading

0 comments on commit b4747c8

Please sign in to comment.