Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages when server misconfigured (#1520)
<!-- Thank you for your Pull Request. Please provide a description above and review the requirements below. Bug fixes and new features should include tests. --> ## Motivation <!-- Explain the context and why you're making that change. What is the problem you're trying to solve? If a new feature is being added, describe the intended use case that feature fulfills. --> Relates to #1435 This PR is trying out a way to improve the error message shown when something is misconfigured. Currently running the server binary (`cargo run` in the `svix-server/` folder) panics when some needed config is missing. e.g. `listen_address` not set ``` thread 'main' panicked at svix-server/src/cfg.rs:550:10: Error loading configuration: Error { tag: Tag::Default, profile: Some(Profile(Uncased { string: "default" })), metadata: None, path: [], kind: MissingField("listen_address"), prev: None } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` e.g. `jwt_secret` not set - in this case the error message doesn't indicate the missing field due to an issue with it coming from an inlined struct inside `ConfigurationInner` - <SergioBenitez/Figment#80> ``` thread 'main' panicked at svix-server/src/cfg.rs:550:10: Error loading configuration: Error { tag: Tag::Default, profile: Some(Profile(Uncased { string: "default" })), metadata: None, path: [], kind: Message("data did not match any variant of untagged enum JwtSigningConfig"), prev: None } ``` ## Solution <!-- Summarize the solution and provide any necessary context needed to understand the code change. --> If `cfg::load()` errors out, terminate with exit code 1 and print the formatted error to stderr. I tried switching to using `anyhow::Result` for `main()` and `cfg::load()` to make propagating errors with human friendly context easier. ``` Error: failed to extract configuration Caused by: missing field `listen_address` ``` Check upfront that `jwt_secret` is set and override the error message to be more helpful due to <SergioBenitez/Figment#80> ``` Error: failed to extract configuration Caused by: missing field `jwt_secret` ```
- Loading branch information