-
Notifications
You must be signed in to change notification settings - Fork 21
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
Only warn about unknown config options instead of rejecting them #631
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not bad. My only complaint is the wrong base branch. (This PR won't be included in v1.2, will it?)
9215bf2
to
4566091
Compare
I've pushed a new version that delays the warning until logging is initialized. In case there is an error (and logging won't be initialized), the warning is embedded in the error message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better (for the ones who read logs 🪵 at all).
if err := c.Validate(); err != nil { | ||
return nil, errors.Wrap(err, "invalid configuration") | ||
msg := "invalid configuration" | ||
if warn := c.DecodeWarning; warn != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's warn
for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shorthand for the longer name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit too much of shorthand. But this is a matter of opinion. Same for "invalid configuration".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying hard to avoid breaking the next line, especially somewhere in the middle of the format string.
pkg/config/config.go
Outdated
if err := c.Validate(); err != nil { | ||
return nil, errors.Wrap(err, "invalid configuration") | ||
msg := "invalid configuration" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a const or even inlined.
}, | ||
{ | ||
name: "mini-with-unknown", | ||
input: miniConf + "\nunknown: 42", | ||
output: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only one of its kind. You've made the existing if below obsolete.
4566091
to
0f0c03d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a similar change in icingadb-migrate? This is more of a manual one-shot tool, so making it an error there right away shouldn't break anything.
You are right. To be even more specific, there are three kinds of users:
- have done migration – won't use the tool again – not affected
- doing migration – affected on interrupt – solutions:
- wait with the update
- just adjust the config
- didn't start migration – didn't use the tool yet – not affected by my change as such (or yours)
if err := c.Validate(); err != nil { | ||
return nil, errors.Wrap(err, "invalid configuration") | ||
msg := "invalid configuration" | ||
if warn := c.DecodeWarning; warn != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit too much of shorthand. But this is a matter of opinion. Same for "invalid configuration".
…them This makes the change from #605 more suitable for the v1.1.1 bug fix release because this way, no new fatal errors are added while keeping the helpful information in a warning.
0f0c03d
to
d11f03d
Compare
This is a quick proof of concept for an idea I had how to make #605 more suitable for a bug fix release.
Currently, it would just fail with an error. This PR basically parses the config like v1.1.0 did, but additionally parses the config a second time with
yaml.DisallowUnknownField()
(like the current master and therefore v1.2 will do) and issue a warning if it returns an error.The
icingadb-migrate
command still treats unknown options as an error. This is more of a manual one-shot tool, so making it an error there right away shouldn't break anything.Tests
Config with unknown options and other errors
First prints error and then additionally the warning:
Unknown option in an otherwise valid config
Logs the warning and then continues to run: