Refactor golangci-lint configuration and improve error handling

- Updated .golangci.yml to enable default linters and refine suppression rules, enhancing code quality visibility.
- Improved error handling in cmd/root.go by explicitly discarding low-value error messages during fatal exits for consistency with errcheck posture.
- Added best-effort error handling in various locations across the codebase, ensuring that non-critical errors are logged without affecting overall functionality.
- Introduced a new writeMetricsText function to streamline metrics output, improving code clarity and maintainability.
This commit is contained in:
2026-05-27 18:51:33 -05:00
parent feda55e225
commit 843772e9f7
6 changed files with 129 additions and 105 deletions
+5 -5
View File
@@ -72,7 +72,7 @@ var rootCmd = &cobra.Command{
Err(err).
Str("config_path", configPath).
Msg("Failed to create default configuration")
fmt.Fprintf(os.Stderr, "Error: Failed to create default config at %s: %v\n", configPath, err)
_, _ = fmt.Fprintf(os.Stderr, "Error: Failed to create default config at %s: %v\n", configPath, err) // explicit discard for fatal stdio path (consistent with errcheck posture; low-value on exit)
os.Exit(1)
}
@@ -88,7 +88,7 @@ var rootCmd = &cobra.Command{
Err(err).
Str("config_path", configPath).
Msg("Failed to load configuration")
fmt.Fprintf(os.Stderr, "Error: Failed to load configuration from %s: %v\n", configPath, err)
_, _ = fmt.Fprintf(os.Stderr, "Error: Failed to load configuration from %s: %v\n", configPath, err) // explicit discard for fatal stdio path (consistent with errcheck posture; low-value on exit)
os.Exit(1)
}
}
@@ -113,7 +113,7 @@ var rootCmd = &cobra.Command{
logger.Logger.Error().
Err(err).
Msg("Configuration validation failed")
fmt.Fprintf(os.Stderr, "Error: Invalid configuration: %v. Please fix the config file and try again.\n", err)
_, _ = fmt.Fprintf(os.Stderr, "Error: Invalid configuration: %v. Please fix the config file and try again.\n", err) // explicit discard for fatal stdio path (consistent with errcheck posture; low-value on exit)
os.Exit(1)
}
@@ -134,7 +134,7 @@ var rootCmd = &cobra.Command{
logger.Logger.Error().
Err(err).
Msg("Failed to initialize steamcache")
fmt.Fprintf(os.Stderr, "Error: Failed to initialize steamcache: %v. Check sizes in config.\n", err)
_, _ = fmt.Fprintf(os.Stderr, "Error: Failed to initialize steamcache: %v. Check sizes in config.\n", err) // explicit discard for fatal stdio path (consistent with errcheck posture; low-value on exit)
os.Exit(1)
}
@@ -143,7 +143,7 @@ var rootCmd = &cobra.Command{
if err := sc.Run(); err != nil {
logger.Logger.Error().Err(err).Msg("steamcache2 Run failed")
fmt.Fprintf(os.Stderr, "Error: steamcache2 run error: %v\n", err)
_, _ = fmt.Fprintf(os.Stderr, "Error: steamcache2 run error: %v\n", err) // explicit discard for fatal stdio path (consistent with errcheck posture; low-value on exit)
os.Exit(1)
}