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

[oximeter] Use fmt::Display for TOML errors #6365

Merged
merged 1 commit into from
Aug 16, 2024
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Aug 16, 2024

Currently, the oximeter::use_timeseries! macro uses fmt::Debug to display errors generating timeseries types, such as errors parsing the TOML schema. This results in kind of hard to interpret error output. For example:

error: Failed to generate timeseries types from '/home/eliza/Code/oxide/omicron/oximeter/impl/../oximeter/schema/sensor-measurement.toml': Toml("TOML parse error at line 8, column 6\n  |\n8 |     {\n  |      ^\ninvalid inline table\nexpected `}`\n")
 --> gateway/src/metrics.rs:7:27
  |
7 | oximeter::use_timeseries!("sensor-measurement.toml");
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^

Note that the toml crate very kindly tries to give us a nice ASCII graphic pointing at the location where the parse error occurred, but because the strings are formatted using fmt::Debug, it's not particularly comprehensible.

This commit changes the macro to use fmt::Display, instead, so that the multi-line diagnostic output from the TOML parser is more readable. Now, it looks like this:

error: Failed to generate timeseries types from '/home/eliza/Code/oxide/omicron/oximeter/impl/../oximeter/schema/sensor-measurement.toml':
       TOML deserialization error: TOML parse error at line 8, column 6
         |
       8 |     {
         |      ^
       invalid inline table
       expected `}`
 --> gateway/src/metrics.rs:7:27
  |
7 | oximeter::use_timeseries!("sensor-measurement.toml");
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^

I cherry-picked this change from #6354, since it seemed like a self-contained change that could easily land on its own.

Currently, the `oximeter::use_timeseries!` macro uses `fmt::Debug` to
display errors generating timeseries types, such as errors parsing the
TOML schema. This results in kind of hard to interpret error output. For
example:

```
error: Failed to generate timeseries types from '/home/eliza/Code/oxide/omicron/oximeter/impl/../oximeter/schema/sensor-measurement.toml': Toml("TOML parse error at line 8, column 6\n  |\n8 |     {\n  |      ^\ninvalid inline table\nexpected `}`\n")
 --> gateway/src/metrics.rs:7:27
  |
7 | oximeter::use_timeseries!("sensor-measurement.toml");
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^

```

Note that the `toml` crate very kindly tries to give us a nice ASCII
graphic pointing at the location where the parse error occurred, but
because the strings are formatted using `fmt::Debug`, it's not
particularly comprehensible.

This commit changes the macro to use `fmt::Display`, instead, so that
the multi-line diagnostic output from the TOML parser is more readable.
Now, it looks like this:
```
error: Failed to generate timeseries types from '/home/eliza/Code/oxide/omicron/oximeter/impl/../oximeter/schema/sensor-measurement.toml':
       TOML deserialization error: TOML parse error at line 8, column 6
         |
       8 |     {
         |      ^
       invalid inline table
       expected `}`
 --> gateway/src/metrics.rs:7:27
  |
7 | oximeter::use_timeseries!("sensor-measurement.toml");
  |                           ^^^^^^^^^^^^^^^^^^^^^^^^^

```
@hawkw hawkw requested a review from bnaecker August 16, 2024 19:50
@hawkw hawkw marked this pull request as ready for review August 16, 2024 19:50
@hawkw hawkw self-assigned this Aug 16, 2024
Copy link
Collaborator

@bnaecker bnaecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much nicer, thanks!

@hawkw hawkw merged commit c28455a into main Aug 16, 2024
22 checks passed
@hawkw hawkw deleted the eliza/oximeter-err-display branch August 16, 2024 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants