Skip to content

Conversation

@rhamzeh
Copy link
Member

@rhamzeh rhamzeh commented Nov 14, 2025

Description

$ ./dist/fga --config ./bla.yaml --debug=true version 
Warning: Failed to load config file ./bla.yaml: While parsing config: yaml: line 3: found unexpected end of stream
$ ./dist/fga --config ./bla.yaml --debug=false version 
Warning: Failed to load config file. Use --debug=true or set FGA_DEBUG=true for details.
Scenario Behavior
Config file not found (auto-discovery) ✅ Silent - continues normally
Config file found with valid YAML ✅ Shows "Using config file: /path/to/.fga.yaml"
Config file found with invalid YAML ⚠️ Shows minimal warning
Invalid YAML + --debug=true flag ⚠️ Shows detailed warning with file path and error
Invalid YAML + FGA_DEBUG=true env var ⚠️ Shows detailed warning with file path and error
Explicit --config with missing/invalid file ⚠️ Shows warning

Note: these will only warn and the actual command will continue

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

closes #608

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Bug Fixes
    • The CLI now warns users when YAML configuration files fail to parse, instead of silently ignoring parsing errors.
    • Detailed error information is available through debug mode using the --debug flag or FGA_DEBUG=true environment variable.

Copilot AI review requested due to automatic review settings November 14, 2025 17:30
@rhamzeh rhamzeh requested a review from a team as a code owner November 14, 2025 17:30
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 14, 2025

Walkthrough

The changes add warning visibility for YAML parsing errors in the .fga.yaml configuration file. A new debug mode detection function was introduced, and config loading logic now emits warnings when parsing fails instead of silently ignoring the error, with optional detailed error output in debug mode.

Changes

Cohort / File(s) Summary
Changelog documentation
CHANGELOG.md
Added Unreleased changelog entry documenting that the CLI now warns users about YAML parsing errors in .fga.yaml config file instead of ignoring them, with guidance to use --debug or FGA_DEBUG=true for detailed messages.
Config initialization logic
cmd/root.go
Added isDebugMode() function to detect debug status from --debug flag or FGA_DEBUG environment variable. Enhanced initConfig() error handling to emit warnings when config file parsing fails, with detailed error output in debug mode and generic suggestions otherwise. Added "errors" package import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Review isDebugMode() logic for correct flag and environment variable handling
  • Verify error handling flow in initConfig() correctly distinguishes between missing files (harmless) and parse errors (warn)
  • Confirm warning messages are user-friendly and properly guide users to debug mode options

Suggested reviewers

  • ewanharris

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title directly and concisely describes the main change: adding a warning when the config file is invalid, which aligns with the primary objective of surfacing errors that were previously silent.
Linked Issues check ✅ Passed The PR successfully addresses the core coding requirement from issue #608: detecting invalid config files and warning users with error details in debug mode, while maintaining graceful fallback behavior.
Out of Scope Changes check ✅ Passed All changes are focused on config file error handling in CHANGELOG.md and cmd/root.go, directly supporting the linked issue objectives with no extraneous modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/warn-on-config-invalid

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds warning messages when the CLI encounters invalid YAML syntax in configuration files, addressing issue #608. Previously, parse errors were silently ignored, making it difficult for users to debug configuration problems.

Key changes:

  • Introduced isDebugMode() function to check debug flags before cobra initialization
  • Added error handling to distinguish between "config file not found" (silent) and "config parsing error" (warning)
  • Updated CHANGELOG to document the new behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
cmd/root.go Implemented warning messages for config parsing errors with debug mode support
CHANGELOG.md Documented the new warning behavior for invalid YAML config files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57ff47b and e96d7de.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • cmd/root.go (3 hunks)
🧰 Additional context used
🪛 GitHub Check: Lints
cmd/root.go

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

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Cleanup artifacts
  • GitHub Check: Test Release Process
  • GitHub Check: Tests
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
CHANGELOG.md (1)

10-11: LGTM! Clear and helpful changelog entry.

The entry accurately describes the fix and provides clear guidance to users on how to obtain detailed error messages.

cmd/root.go (2)

21-21: LGTM! Import is correctly used.

The errors package is properly imported for the errors.As() type assertion on line 153.


150-161: LGTM! Error handling logic is correct.

The enhanced error handling properly distinguishes between:

  • Config file not found (silent continuation, as intended)
  • Config file found but failed to parse (warning with appropriate verbosity)

The use of errors.As() for type checking is correct, and viperInstance.ConfigFileUsed() is safe to call here since we know the file was found (just failed to parse).

Comment on lines +55 to +80
// 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
}
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.

@rhamzeh rhamzeh marked this pull request as draft November 14, 2025 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI silently ignores .fga.yaml config file when YAML parsing fails

2 participants