cmd: Adjust config load logs/errors #6032
Merged
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.
Sometimes, users use Caddyfile file names that don't match our adapter-guessing rules, and this causes the config to be loaded as JSON. The error message is very confusing when that happens. I made some adjustments to improve it.
Before:
After:
Now, we're quickly doing a
json.Unmarshal
just to test that the JSON is valid (there isjson.Validate()
but it only returns a bool and not errors) before returning it to the caller after loading the config file.Also, I moved the adapter log to be after the adapter guessing logic so that it doesn't show up empty in a confusing way in the logs. I also split the stdin and file log messages for clarity.
I'm not sure about the last bit though
; did you mean to use '--adapter'?
is there a better way we could word that without being ambiguous? 🤔 The problems is "what if they actually meant to load JSON" then a mention like this might be confusing for those users. So it's hard to go too far in either direction with the warning.