Conversation
…i18n that needs text and args separately
…i18n that needs text and args separately
…i18n that needs text and args separately
…i18n that needs text and args separately
There was a problem hiding this comment.
Pull request overview
This pull request introduces the ITextArgs interface to enable separation of error text templates from their formatting arguments, primarily to support internationalization (i18n) scenarios. The changes refactor error creation to store format strings and arguments separately rather than pre-formatting them.
Key changes:
- Added
ITextArgsinterface withText()andArgs()methods to expose error templates and arguments - Modified
Errorstruct to include anargsfield and addedTextWithArgs(),Text(), andArgs()methods - Updated all error creation functions (
Newf,Wrapf,NewCodef, etc.) to store format strings and args separately instead of pre-formatting
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| errors/gerror/gerror.go | Defines new ITextArgs interface and updates existing interfaces to embed error instead of declaring Error() string |
| errors/gerror/gerror_error.go | Adds args field to Error struct and implements TextWithArgs(), Text(), and Args() methods |
| errors/gerror/gerror_api.go | Updates error creation functions to store format and args separately; removes fmt import |
| errors/gerror/gerror_api_code.go | Updates code-based error creation functions to store format and args separately; removes fmt import |
| errors/gerror/gerror_api_option.go | Adds Args field to Option struct for deferred formatting support |
| errors/gerror/gerror_error_format.go | Updates Format() to use TextWithArgs() instead of direct text field access |
| errors/gerror/gerror_error_json.go | Changes MarshalJSON receiver from value to pointer (contradicts existing comment) |
| errors/gerror/gerror_z_unit_test.go | Adds Test_TextArgs function to test new interface and updates comment wording |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request refactors the error handling code to improve support for error text formatting with arguments, making it easier to retrieve both the error message template and its arguments (useful for i18n and structured error handling). It introduces the new
ITextArgsinterface, updates error constructors to store format strings and arguments separately, and adds methods to retrieve them. Several usages and tests are updated to reflect these changes.Error formatting and argument support
ITextArgsinterface to allow errors to expose their text template and arguments separately, supporting advanced use cases like internationalization (errors/gerror/gerror.go).Errorstruct to include anargsfield for error arguments, and added methodsTextWithArgs(),Text(), andArgs()to retrieve formatted error text, the template, and arguments respectively (errors/gerror/gerror_error.go). [1] [2]Newf,Wrapf,NewCodef, etc.) to store the format string and arguments separately, rather than pre-formatting the error text (errors/gerror/gerror_api.go,errors/gerror/gerror_api_code.go). [1] [2] [3] [4] [5] [6] [7]Optionstruct and related constructor to handle error arguments (errors/gerror/gerror_api_option.go). [1] [2]Code and test improvements
errors/gerror/gerror_error.go,errors/gerror/gerror_error_format.go). [1] [2]ITextArgsinterface (errors/gerror/gerror_z_unit_test.go).errors/gerror/gerror_api.go,errors/gerror/gerror_api_code.go,errors/gerror/gerror_error_json.go). [1] [2] [3]These changes make error handling more flexible and maintainable, especially for scenarios where error messages need to be localized or programmatically inspected.