diff --git a/examples/core/state_generation/Cargo.toml b/examples/core/state_generation/Cargo.toml index 3f873c2c3b..e9844f1c65 100644 --- a/examples/core/state_generation/Cargo.toml +++ b/examples/core/state_generation/Cargo.toml @@ -10,6 +10,7 @@ perseus = { path = "../../../packages/perseus", features = [ "hydrate" ] } sycamore = "^0.8.1" serde = { version = "1", features = ["derive"] } serde_json = "1" +anyhow = "1" [dev-dependencies] fantoccini = "0.17" diff --git a/examples/core/state_generation/src/templates/incremental_generation.rs b/examples/core/state_generation/src/templates/incremental_generation.rs index 182a440b44..50ef2b61b7 100644 --- a/examples/core/state_generation/src/templates/incremental_generation.rs +++ b/examples/core/state_generation/src/templates/incremental_generation.rs @@ -48,7 +48,7 @@ pub fn get_template() -> Template { #[engine_only_fn] async fn get_build_state( StateGeneratorInfo { path, .. }: StateGeneratorInfo<()>, -) -> Result> { +) -> Result> { // This path is illegal, and can't be rendered // Because we're using incremental generation, we could get literally anything // as the `path` @@ -56,14 +56,13 @@ async fn get_build_state( // This tells Perseus to return an error that's the client's fault, with the // HTTP status code 404 (not found) and the message 'illegal page'. Note that // this is a `BlamedError`, but we could use any error type that - // implements `std::error::Error` (note that this does make `anyhow` a - // bit tricky, if you use it). + // implements `std::error::Error` or can be converted into a boxed `std::error::Error`. return Err(BlamedError { // If we used `None` instead, it would default to 400 for the client and 500 for the // server blame: ErrorBlame::Client(Some(404)), // This is just an example, and you could put any error type here, usually your own - error: std::io::Error::new(std::io::ErrorKind::NotFound, "illegal page"), + error: anyhow::anyhow!("illegal page"), }); } let title = path.clone(); diff --git a/packages/perseus/src/errors.rs b/packages/perseus/src/errors.rs index af11b80c23..3127091a59 100644 --- a/packages/perseus/src/errors.rs +++ b/packages/perseus/src/errors.rs @@ -491,12 +491,12 @@ pub struct BlamedError { pub blame: ErrorBlame, } #[cfg(engine)] -impl BlamedError { +impl> + Send + Sync> BlamedError { /// Converts this blamed error into an internal boxed version that is /// generic over the error type. pub(crate) fn into_boxed(self) -> GenericBlamedError { BlamedError { - error: Box::new(self.error), + error: self.error.into(), blame: self.blame, } } @@ -504,7 +504,9 @@ impl BlamedError { // We should be able to convert any error into this easily (e.g. with `?`) with // the default being to blame the server #[cfg(engine)] -impl From for BlamedError { +impl> + Send + Sync> From + for BlamedError +{ fn from(error: E) -> Self { Self { error, diff --git a/packages/perseus/src/template/fn_types.rs b/packages/perseus/src/template/fn_types.rs index 53ceeb2f38..a4c5a3b383 100644 --- a/packages/perseus/src/template/fn_types.rs +++ b/packages/perseus/src/template/fn_types.rs @@ -172,8 +172,10 @@ impl From for BlamedGeneratorResult Self::Ok(val) } } -impl - From>> for BlamedGeneratorResult +impl< + S: Serialize + DeserializeOwned + MakeRx, + E: Into> + Send + Sync, + > From>> for BlamedGeneratorResult { fn from(val: Result>) -> Self { match val { @@ -188,8 +190,8 @@ impl From for BlamedGeneratorResult { Self::Ok(val) } } -impl From>> - for BlamedGeneratorResult +impl> + Send + Sync> + From>> for BlamedGeneratorResult { fn from(val: Result>) -> Self { match val {