Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

## [Unreleased]

Fixed:
- CLI now warns users when `.fga.yaml` config file has YAML parsing errors instead of silently ignoring them. Use `--debug` flag or set `FGA_DEBUG=true` for detailed error messages

## [0.7.8] - 2025-11-05

Fixed:
Expand Down
40 changes: 40 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package cmd

import (
"errors"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -51,6 +52,33 @@
}
}

// isDebugMode checks if debug mode is enabled via --debug flag or FGA_DEBUG env var.
// We are not following cobra's built-in flag checking here because we want to determine
// debug mode status before cobra parses flags (to control logging during initConfig).
// The precedence is:
// 1. Command-line flag --debug
// 2. Environment variable FGA_DEBUG
// Other areas in the code should parse the flag using cobra after initialization rather
// than rely on this function.
func isDebugMode() bool {
// Command-line flag takes precedence
for _, arg := range os.Args {
if arg == "--debug=true" {
return true
}
if arg == "--debug=false" {

Check failure on line 69 in cmd/root.go

View workflow job for this annotation

GitHub Actions / Lints

missing whitespace above this line (invalid statement above if) (wsl_v5)
return false
}
}

// Check environment variable first
if os.Getenv("FGA_DEBUG") == "true" {
return true
}

return false
}
Comment on lines +55 to +80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix bugs in debug mode detection and correct misleading comment.

The function has several issues:

  1. Missing support for --debug without explicit value: Line 99 defines --debug as a boolean flag, so --debug (without =true) should enable debug mode, but this implementation only checks for --debug=true and --debug=false.

  2. Misleading comment on line 74: The comment states "Check environment variable first" but the code actually checks the command-line flag first (lines 65-72), then the environment variable.

  3. Style issue (linter): Missing whitespace before line 69.

Apply this diff to fix all issues:

 func isDebugMode() bool {
 	// Command-line flag takes precedence
 	for _, arg := range os.Args {
+		if arg == "--debug" {
+			return true
+		}
 		if arg == "--debug=true" {
 			return true
 		}
+
 		if arg == "--debug=false" {
 			return false
 		}
 	}
 
-	// Check environment variable first
+	// Fall back to environment variable
 	if os.Getenv("FGA_DEBUG") == "true" {
 		return true
 	}
 
 	return false
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// isDebugMode checks if debug mode is enabled via --debug flag or FGA_DEBUG env var.
// We are not following cobra's built-in flag checking here because we want to determine
// debug mode status before cobra parses flags (to control logging during initConfig).
// The precedence is:
// 1. Command-line flag --debug
// 2. Environment variable FGA_DEBUG
// Other areas in the code should parse the flag using cobra after initialization rather
// than rely on this function.
func isDebugMode() bool {
// Command-line flag takes precedence
for _, arg := range os.Args {
if arg == "--debug=true" {
return true
}
if arg == "--debug=false" {
return false
}
}
// Check environment variable first
if os.Getenv("FGA_DEBUG") == "true" {
return true
}
return false
}
// isDebugMode checks if debug mode is enabled via --debug flag or FGA_DEBUG env var.
// We are not following cobra's built-in flag checking here because we want to determine
// debug mode status before cobra parses flags (to control logging during initConfig).
// The precedence is:
// 1. Command-line flag --debug
// 2. Environment variable FGA_DEBUG
// Other areas in the code should parse the flag using cobra after initialization rather
// than rely on this function.
func isDebugMode() bool {
// Command-line flag takes precedence
for _, arg := range os.Args {
if arg == "--debug" {
return true
}
if arg == "--debug=true" {
return true
}
if arg == "--debug=false" {
return false
}
}
// Fall back to environment variable
if os.Getenv("FGA_DEBUG") == "true" {
return true
}
return false
}
🧰 Tools
🪛 GitHub Check: Lints

[failure] 69-69:
missing whitespace above this line (invalid statement above if) (wsl_v5)

🤖 Prompt for AI Agents
In cmd/root.go around lines 55 to 80, update isDebugMode to correctly detect the
--debug flag without an explicit value, fix the misleading comment and add the
missing blank line for linting: treat any arg equal to "--debug" as true, handle
forms "--debug=true" and "--debug=false" by parsing the value after the '='
(accepting standard boolean strings), keep command-line flag precedence over
FGA_DEBUG (so only check the env var if no flag was present), change the comment
that currently says "Check environment variable first" to accurately reflect
that the code checks the command-line flag first then the env var, and add the
required blank line before the environment-variable check for style compliance.


func init() {
cobra.OnInitialize(initConfig)

Expand Down Expand Up @@ -117,8 +145,20 @@
}

// If a config file is found, read it in.
if err := viperInstance.ReadInConfig(); err == nil {

Check failure on line 148 in cmd/root.go

View workflow job for this annotation

GitHub Actions / Lints

`if err == nil` has complex nested blocks (complexity: 5) (nestif)
fmt.Fprintln(os.Stderr, "Using config file:", viperInstance.ConfigFileUsed())
} else {
// Check if error is due to config file not found (this is OK, we continue silently)
var configFileNotFoundError viper.ConfigFileNotFoundError
if !errors.As(err, &configFileNotFoundError) {
// Config file exists but failed to parse - show warning
if isDebugMode() {
fmt.Fprintf(os.Stderr, "Warning: Failed to load config file %s: %v\n",
viperInstance.ConfigFileUsed(), err)
} else {
fmt.Fprintln(os.Stderr, "Warning: Failed to load config file. Use --debug=true or set FGA_DEBUG=true for details.")
}
}
}

viperInstance.SetEnvPrefix("FGA")
Expand Down
Loading