Conversation
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
📝 WalkthroughWalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pkg/config/config.go (2)
143-143: Add a doc comment for this exported function.The new exported function lacks documentation. Consider adding a doc comment explaining the purpose and the
errNotFoundparameter semantics.📝 Suggested documentation
+// LoadConfigOptional reads configuration from file or environment variables. +// If errNotFound is false, a missing config file is silently ignored and defaults are used. +// If errNotFound is true, a missing config file results in an error (same as LoadConfig). func LoadConfigOptional(path string, errNotFound bool) (Config, error) {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/config/config.go` at line 143, Add a Go doc comment for the exported function LoadConfigOptional that briefly describes its purpose (loading configuration from the given path) and explains the semantics of the errNotFound boolean (e.g., when true, treat missing file as non-fatal and return default/empty Config; when false, return an error if the file is missing), and include any important behavior such as return values and error conditions; place the comment immediately above the LoadConfigOptional function declaration.
223-228: Consider simplifying the double-negative condition for readability.The condition
!(errors.As(err, ¬Found) && !errNotFound)is logically correct but hard to parse due to the double negation. An equivalent positive expression would be clearer.♻️ Suggested simplification
if err := viper.ReadInConfig(); err != nil { var notFound viper.ConfigFileNotFoundError - if !(errors.As(err, ¬Found) && !errNotFound) { + if !errors.As(err, ¬Found) || errNotFound { return Config{}, err } + // Config file not found but optional; continue with defaults }This reads as: "return the error if it's not a file-not-found error, or if file-not-found should be treated as an error."
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/config/config.go` around lines 223 - 228, The current double-negative condition after viper.ReadInConfig makes the logic hard to read; replace the expression `!(errors.As(err, ¬Found) && !errNotFound)` with the equivalent positive check `!errors.As(err, ¬Found) || errNotFound` so the block around viper.ReadInConfig, the viper.ConfigFileNotFoundError variable, and the errNotFound flag clearly reads: if the error is not a ConfigFileNotFoundError or file-not-found should be treated as an error, return the error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/config/config.go`:
- Line 143: Add a Go doc comment for the exported function LoadConfigOptional
that briefly describes its purpose (loading configuration from the given path)
and explains the semantics of the errNotFound boolean (e.g., when true, treat
missing file as non-fatal and return default/empty Config; when false, return an
error if the file is missing), and include any important behavior such as return
values and error conditions; place the comment immediately above the
LoadConfigOptional function declaration.
- Around line 223-228: The current double-negative condition after
viper.ReadInConfig makes the logic hard to read; replace the expression
`!(errors.As(err, ¬Found) && !errNotFound)` with the equivalent positive
check `!errors.As(err, ¬Found) || errNotFound` so the block around
viper.ReadInConfig, the viper.ConfigFileNotFoundError variable, and the
errNotFound flag clearly reads: if the error is not a ConfigFileNotFoundError or
file-not-found should be treated as an error, return the error.
Summary by CodeRabbit