private/app/launcher: unwrap errors fully to avoid hiding cause#4783
Draft
MatthewCroughan wants to merge 1 commit intoscionproto:masterfrom
Draft
private/app/launcher: unwrap errors fully to avoid hiding cause#4783MatthewCroughan wants to merge 1 commit intoscionproto:masterfrom
MatthewCroughan wants to merge 1 commit intoscionproto:masterfrom
Conversation
Contributor
Author
|
It is worth noting that the inverse case (a config option being missing when it is required) is not fixed, and still behaves badly despite this pr. For example when
|
As an example, before this commit, when a key was removed from the
struct that defines available configuration option for the toml file for
a given application such as the scion-dispatcher, it would fail without
reporting what key is present when it should be removed from the config
file, as follows:
error: loading config from file {file=/foo.toml}: strict mode: fields in the document are missing in the target struct
After this commit it will fail more informatively as follows:
error: loading config from file {file=/foo.toml}: strict mode: fields in the document are missing in the target struct &toml.StrictMissingError{Errors:[]t
oml.DecodeError{toml.DecodeError{message:"missing field", line:4, column:1, key:toml.Key{"general", "reconnect_to_dispatcher"}, human:"1| [general]\n2| config_dir = \"/etc/scion\"\n3| id = \"sd\"\n4| reconnect_to_dispatcher = true\n | ~~~~~~~~~~~~~~~~~~~~~
~~ missing field\n5|\n6| [log.console]\n7| level = \"info\""}}}
You can see the reason for the failure is the presence of the "reconnect_to_dispatcher" key, which no longer exists
12b58c6 to
6327fa6
Compare
oncilla
reviewed
Jun 17, 2025
| func (a *Application) Run() { | ||
| if err := a.run(); err != nil { | ||
| fmt.Fprintf(a.getErrorWriter(), "fatal error: %v\n", err) | ||
| fmt.Fprintf(a.getErrorWriter(), "fatal error: %v\n %#v\n", err, errors.Unwrap(err)) |
Contributor
There was a problem hiding this comment.
IMO, this still produces hard to read error messages.
Instead, I think you should use errors.As together with toml.StrictMissingError and toml.DecodeError
If error matches -> pretty print to stderr
I would also leave this line unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this commit, when a key was removed from the struct that defines available configuration option for the toml file for a given application such as the scion-dispatcher, it would fail without reporting what key is present when it should be removed from the config file, as follows:
error: loading config from file {file=/foo.toml}: strict mode: fields in the document are missing in the target structAfter this commit it will fail more informatively as follows:
error: loading config from file {file=/foo.toml}: strict mode: fields in the document are missing in the target struct &toml.StrictMissingError{Errors:[]t oml.DecodeError{toml.DecodeError{message:"missing field", line:4, column:1, key:toml.Key{"general", "reconnect_to_dispatcher"}, human:"1| [general]\n2| config_dir = \"/etc/scion\"\n3| id = \"sd\"\n4| reconnect_to_dispatcher = true\n | ~~~~~~~~~~~~~~~~~~~~~ ~~ missing field\n5|\n6| [log.console]\n7| level = \"info\""}}}You can see the reason for the failure is the presence of the "reconnect_to_dispatcher" key, which no longer exists in 0.12, but did in 0.11.
I do not think this PR is necessarily the best way to accomplish or format this, but it was useful for me and is a good way to discuss the issue. If anyone else has a better idea, then please contribute it!