Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error messages when server is misconfigured #1435

Open
tasn opened this issue Sep 13, 2024 · 1 comment
Open

Improve error messages when server is misconfigured #1435

tasn opened this issue Sep 13, 2024 · 1 comment
Labels
server Issues regarding the server component

Comments

@tasn
Copy link
Member

tasn commented Sep 13, 2024

E.g. try not setting jwt_secret and see how confusing the errors are.

@tasn tasn added server Issues regarding the server component grooming labels Oct 4, 2024
svix-onelson added a commit that referenced this issue Nov 19, 2024
<!--
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`
```
@svix-jplatte
Copy link
Member

With #1520 merged, I think what's left here is:

  • retry schedule
  • database config

which produce bad error messages due to #[serde(untagged)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Issues regarding the server component
Projects
None yet
Development

No branches or pull requests

2 participants