Warn when Koanf read fails #47

Merged
Elara6331 merged 3 commits from Hunman/itd:error-handling into master 2023-01-02 09:05:24 +00:00
Contributor

Figured out the problem in issue #32, the toml file syntax was invalid (I had ' instead of " at some values), but there was nothing in the logs about it.

Moved the config reading (and watching) into the same function, which logs the error as a warning.

I wanted to try moving the whole if into a separate function, but I kept getting errors when I tried to extract the path from the File, so I have that attempt in a separate branch not in this pull request: 5a84bf8148

Figured out the problem in issue #32, the toml file syntax was invalid (I had `'` instead of `"` at some values), but there was nothing in the logs about it. Moved the config reading (and watching) into the same function, which logs the error as a warning. I wanted to try moving the whole `if` into a separate function, but I kept getting errors when I tried to extract the `path` from the `File`, so I have that attempt in a separate branch not in this pull request: https://gitea.arsenm.dev/Hunman/itd/commit/5a84bf81489d3dc57f197f5feef5521950645ba5
Hunman added 2 commits 2022-12-30 01:46:35 +00:00
Load the configs in one function, which handles the error too
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
a254762288
We are doing the same thing to global and user level config, so it makes
sense to do it in a separate function
Loaded in the fmt package, so we can print out everything in one useful
error (actually warning) message
Elara6331 requested changes 2023-01-02 03:01:06 +00:00
Elara6331 left a comment
Owner

Other than these two minor changes, it looks good, thanks!

Other than these two minor changes, it looks good, thanks!
@ -71,0 +68,4 @@
provider := file.Provider(filename)
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil {
log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
Owner
- log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
+ log.Warn().Str("filename", filename).Err(cfgError).Msg("Error while trying to read config file")
```diff - log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error())) + log.Warn().Str("filename", filename).Err(cfgError).Msg("Error while trying to read config file") ```
Hunman marked this conversation as resolved
@ -76,2 +79,3 @@
k.Load(provider, toml.Parser())
if cfgError := k.Load(provider, toml.Parser()); cfgError != nil {
log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
Owner

Same as above

- log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error()))
+ log.Warn().Str("filename", filename).Err(cfgError).Msg("Error while trying to read config file")
Same as above ```diff - log.Warn().Msg(fmt.Sprintf("Error while trying to read %s: %s\n", filename, cfgError.Error())) + log.Warn().Str("filename", filename).Err(cfgError).Msg("Error while trying to read config file") ```
Hunman marked this conversation as resolved
Hunman added 1 commit 2023-01-02 08:59:57 +00:00
Replacing format strings with magic
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
7e4c916f0e
Author
Contributor

Huh, neat

image

Huh, neat ![image](/attachments/16e3f7bd-35bf-4cac-a8f4-4d4b36ae3e9c)
Elara6331 approved these changes 2023-01-02 09:05:01 +00:00
Elara6331 left a comment
Owner

Thanks, merging now

Thanks, merging now
Elara6331 merged commit 5f5c67f7cc into master 2023-01-02 09:05:24 +00:00
Sign in to join this conversation.
No description provided.