Code Cleanup and Simplification #1902
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Code Cleanup and Simplification
Summary
This pull request focuses on code refactoring and cleanup across several internal packages. The primary changes include simplifying redundant error formatting in the CLI module, streamlining model normalization logic in the core chatter module, and removing an unused parameter from the vendor management system.
Files Changed
internal/cli/flags.gofmt.Sprintfcalls withinfmt.Errorf.fmt.Errorfnatively supports format verbs. Wrapping afmt.Sprintfcall insidefmt.Errorf("%s", ...)is unnecessary, adds extra allocations, and reduces readability.internal/core/chatter.goSendmethod.if/elseblock where both branches assignedo.modeltoopts.Model. This has been collapsed into a single, direct assignment.internal/plugins/ai/vendors.govendors ...Vendorfrom theClearmethod signature.Code Changes
Redundant Formatting Cleanup
In
internal/cli/flags.go, multiple instances of nested formatting were simplified:Logic Simplification
In
internal/core/chatter.go, the redundant conditional check was removed:API Cleanup
In
internal/plugins/ai/vendors.go, the method signature was updated to reflect its actual behavior:Reason for Changes
The main driver for these changes is technical debt reduction.
fmt.Sprintfcalls reduces the number of string allocations and function calls during error handling.chatter.gomakes the intent of the code (always using the normalized model name) much clearer.Clearmethod signature was misleading as it suggested it could clear specific vendors, while it actually performed a full reset.Impact of Changes
VendorsManager.Clear()is a breaking change for any internal callers that were passing arguments to this function. However, since the arguments were ignored, the logic remains identical.Test Plan
internal/cliandinternal/coreto ensure error messages and model assignments still behave as expected.VendorsManager.Clear()are updated (if any existed).Additional Notes
These changes produce no functional change and are zero risk, however, they do improve some of the error message
outputs.
For example, introducing a syntax error in
~/.config/fabric/config.ymland then running this:After the fixes,