https://linen.dev logo
How do I marry error-stack with shuttle_service?
# help
s
In
shutttle_service::main
I have (inlined for brevity)
Copy code
rust
let val = secret_store.get(prop)
        .ok_or_else(|| ConfigurationMissingError)
        .into_report()
        .attach_printable(format!("Could not get {prop} from Secrets"))?
        .parse::<u64>()
        .map_err(|e| ConfigurationParsingError)
        .into_report()
        .attach_printable(format!("Could not parse {prop}"))?;

// elsewhere in lib.rs
enum StartupError {
    ConfigurationMissingError,
    ConfigurationParsingError,
}
it results in >
?
couldn't convert the error to
shuttle_service::Error
if I add
.map_err(|e| anyhow!("{e}"))
I get following instead: > type mismatch resolving
<impl std::future::Future<Output = std::result::Result<std::boxed::Box<(dyn shuttle_service::Service + 'static)>, error_stack::Report<shuttle_service::Error>>> as std::future::Future>::Output == std::result::Result<std::boxed::Box<dyn shuttle_service::Service>, shuttle_service::Error>
EDIT: I've thought about it a bit and I'm over-complicating things, I don't need so much complexity around reading the startup configuration, I can just use `anyhow!`s here, I'm going to do that:
Copy code
rust
    secret_store.get(prop)
        .ok_or_else(|| anyhow!("Could not get {prop} from Secrets"))?
        .parse::<T>()
        .map_err(|e| anyhow!("Could not parse {prop}, {e}"))?
But I'm still curious, what would be the way to fix it.
s
The easiest is
.map_err(CustomError::new)?
because
CustomError
is just an alias for
anyhow
https://github.com/shuttle-hq/shuttle/blob/b00671dc32b341ad6dafba0e7ac1fb1b803a68f5/examples/rocket/postgres/src/lib.rs#L44