chore: refactor formatter and value functions#3
Merged
Conversation
Refactor the Value functions and the formatter to fix an error with the formatter when the key was not a string. The Value* functions were refactored to be more consistent. Now Value* returnas always the first occurrence and Values* returns all occurrences of a key. Now the formatter will print all the keys in the reverse order of creation (most recent first). Other formatters were added for convenience.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors how key-value pairs are retrieved and formatted in errors, fixes a formatter error when keys aren’t strings, and adds convenience formatters.
- Extracted and unified
Value*/Values*helpers intovalue.goto consistently return most recent or all occurrences. - Revised formatter logic in
formatter.goto useValueAllSlicewith newwrite*helpers and introducedRootErrorFormatterandRootErrorKVFormater. - Updated
KVconstructor andstringifyinkv.goand adjusted tests informatter_test.gofor multi-type values.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| value.go | New dedicated file for Value/Values/Map helpers |
| kv.go | Adjusted KV constructor and improved stringify |
| formatter.go | Refactored main formatter, added helper writers & new formatters |
| formatter_test.go | Test updated for mixed-type key-value formatting |
| error.go | Removed duplicate retrieval functions, streamlined Error |
| error_test.go | Removed empty test file |
Comments suppressed due to low confidence (2)
formatter.go:8
- The comment refers to
FullFormatterbut the actual function and constant are namedFullFormater(one ‘t’). Update the comment to match the code or rename the function for consistency.
// DefaultFormatter is the default formatter used when no custom formatter is set.
formatter.go:46
- The function name
FullFormater(and similarlyRootErrorKVFormater) is misspelled—‘Formatter’ is typically spelled with two ‘t’s. Consider renaming toFullFormatterfor clarity.
func FullFormater(err error) string {
xico42
approved these changes
Jun 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Refactor the Value functions and the formatter to fix an error with the formatter when the key was not a string.
The Value* functions were refactored to be more consistent. Now Value* returnas always the first occurrence and Values* returns all occurrences of a key.
Now the formatter will print all the keys in the reverse order of creation (most recent first).
Other formatters were added for convenience.