iliana / rust-crowbar

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)
https://docs.rs/crowbar
Apache License 2.0
197 stars 16 forks source link

format errors for human consumption #43

Closed softprops closed 5 years ago

softprops commented 6 years ago

this addresses #42 I've found that print a Debug implementation of errors lends itself toward communication less useful information that Display which lends itself more towards communicating errors for humans

softprops commented 6 years ago

What do you think about returning the Display format but logging the Debug format via eprintln!?

I'm cool with that. That's also what Debug is really for. Debug logging :) I'll push a change up for that in a bit

softprops commented 6 years ago

I'm cool with that. That's also what Debug is really for. Debug logging :) I'll push a change up for that in a bit

@ilianaw I replied too soon. I'm ambivalent about using eprintln! that because logging that that users many not want but will be forced to have. What do you think about a debug! log message. That would be off unless a logging implementation ( like env_logger ) turned debug log level logging on. Thoughts?

iliana commented 6 years ago

That's fine to me. I think we should specify a default log level of debug if we can, but I worry about that turning on debug for some particularly loud crates.

Maybe we want info to be the default log level and actually log at the error! level.

softprops commented 6 years ago

I just realized this would require a new dependency on the log crate which isn't necessarily bad as its a common substrate for much of the rust application ecosystem but I just wanted to call it out as a new dependency

softprops commented 6 years ago

Pushed up a change to error! log the Debug fmt. I'd opt not to set a default log level because that really belongs in an applications.

here's an example from one of my crowbar lambdas at work

lambda!(|event, _| {
    drop(env_logger::try_init());
    info!("recv {:?}", event);
    CORE.with(|c| {
        let mut core = c.borrow_mut();
        let work = assign(
            &core.handle(),
            envy::from_env::<Config>().map_err(|e| format!("{}", e))?,
        );
        core.run(work)
    })?;
    Ok(())
});
softprops commented 6 years ago

I wanted to drop a link here for reference on how the aws runtime maps error messages - https://docs.aws.amazon.com/lambda/latest/dg/python-exceptions.html

softprops commented 5 years ago

Yep! Happy to iterate if needed :)