fix: don't panic, only accept typed log Fields #222
+17
−98
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.
fixes #221
A breaking change like this is unfortunate, but I feel strongly that it is the best path forward. The above issue gives more background, but briefly, with slog as it is without this PR, passing bad arguments to log calls will cause a panic.
With this PR, slog will not panic, and furthermore, we will have build-time checks that log call arguments are correct.
The breaking changes are that log calls of this form:
are no longer supported, and any code that builds an array of log fields needs to be of type
[]slog.Fieldrather than[]any.This results in a relatively small number of code changes in a big repo like coder/coder: https://github.com/coder/coder/compare/spike/slog-dont-panic?expand=1
slog's README.md has this to say in the "Why?" section:
At some point the decision was made to stray from this principle and we ended up in a place with no static type checking where it is easy to pass invalid fields, and we allowed a usage without syntax grouping of key/value pairs. This PR restores us to these principles.