Skip to content

fix(settings): resolve bugs with completions/validation#208

Merged
water-sucks merged 5 commits intonix-community:mainfrom
water-sucks:fix-settings-validation
Apr 3, 2026
Merged

fix(settings): resolve bugs with completions/validation#208
water-sucks merged 5 commits intonix-community:mainfrom
water-sucks:fix-settings-validation

Conversation

@water-sucks
Copy link
Copy Markdown
Collaborator

@water-sucks water-sucks commented Apr 3, 2026

Some bugs existed with the settings, including:

  • Missing completions/validations
  • --config not validating passed string enum values
  • Panics in certain situations with invalid keys, which screws up completion output

This PR finds those and resolves them, and also uses UnmarshalText() when needed to ensure strong validation of enum keys.

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation and error handling for password input method configuration options.
    • Enhanced configuration completion detection for boolean fields.
    • Refined configuration flag parsing for more robust input handling.

@water-sucks
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

Enhanced password method handling in settings framework by updating reflection API usage, refactoring flag parsing logic, adding password method completion support, and implementing custom unmarshaling for PasswordInputMethod type validation.

Changes

Cohort / File(s) Summary
Settings completion framework
internal/settings/completion.go
Updated reflection calls from deprecated reflect.Ptr to reflect.Pointer, refactored CompleteConfigFlag to use strings.Cut instead of manual slicing, added completion support for root.password_method field, and hardened boolean field detection with nil check.
PasswordInputMethod type support
internal/settings/settings.go
Implemented UnmarshalText method on PasswordInputMethod to validate and parse "stdin", "tty", and "none" values, and updated SetValue to prefer encoding.TextUnmarshaler for custom parsing before kind-based type assignment.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main changes: fixing bugs related to settings completions and validation, which aligns with the PR objectives of addressing missing completions, validation issues, and preventing panics.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.11.4)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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
Copy Markdown

@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.

🧹 Nitpick comments (1)
internal/settings/settings.go (1)

567-575: Preserve field context when UnmarshalText fails.

Returning raw unmarshaler errors here makes diagnostics less consistent than the typed parse branches. Consider wrapping with the config key/field path.

Proposed diff
 			if current.CanAddr() {
 				if unmarshaler, ok := current.Addr().Interface().(encoding.TextUnmarshaler); ok {
 					if err := unmarshaler.UnmarshalText([]byte(value)); err != nil {
-						return err
+						return SettingsError{
+							Field:   key,
+							Message: err.Error(),
+						}
 					}
 					return nil
 				}
 			}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@internal/settings/settings.go` around lines 567 - 575, Wrap errors returned
from unmarshaler.UnmarshalText with a contextual message that includes the
config key/field path so diagnostics match other parse branches: inside the
block where current.CanAddr() and
current.Addr().Interface().(encoding.TextUnmarshaler) are used, change the error
return to wrap the unmarshaler error (e.g. return fmt.Errorf("unmarshal text for
%s: %w", <keyOrFieldPath>, err)) and add fmt to imports if necessary; use the
same identifier used elsewhere for the config key/field path (e.g. key, path, or
fieldPath) to keep messages consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@internal/settings/settings.go`:
- Around line 567-575: Wrap errors returned from unmarshaler.UnmarshalText with
a contextual message that includes the config key/field path so diagnostics
match other parse branches: inside the block where current.CanAddr() and
current.Addr().Interface().(encoding.TextUnmarshaler) are used, change the error
return to wrap the unmarshaler error (e.g. return fmt.Errorf("unmarshal text for
%s: %w", <keyOrFieldPath>, err)) and add fmt to imports if necessary; use the
same identifier used elsewhere for the config key/field path (e.g. key, path, or
fieldPath) to keep messages consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0add7534-165a-4eb6-8a7a-26198b235ec1

📥 Commits

Reviewing files that changed from the base of the PR and between 34d3708 and 7649418.

📒 Files selected for processing (2)
  • internal/settings/completion.go
  • internal/settings/settings.go

@water-sucks water-sucks merged commit 4aa03c2 into nix-community:main Apr 3, 2026
2 checks passed
@water-sucks water-sucks deleted the fix-settings-validation branch April 3, 2026 21:33
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.

1 participant