feat: automatic op#4
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements an automatic operation (Op) feature for error wrapping using errors.With. It adds support for automatically generating an Op based on the caller’s context, allows including line number information for anonymous functions, and refactors some error value functions into a dedicated file.
- Introduces global flags and environment variable support for automatic Op and verbosity.
- Adds functions to retrieve caller information and modify the error chain with automatic Ops.
- Refactors error value functions by moving them to separate files and removing redundant code.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| with.go | Implements automatic Op addition and caller context processing. |
| value.go | Provides error value retrieval functions (new extraction of value logic). |
| kv.go | Updates key-value stringification and simplifies key-value construction. |
| formatter_test.go | Adjusts expected error formatting output to include new key ordering. |
| formatter.go | Updates default formatter selection and refines error string assembly. |
| example/main.go | Demonstrates new error wrapping behavior with automatic Op and flags. |
| error_test.go | Removes old tests, potentially affecting overall test coverage. |
| error.go | Removes several exported value functions, possibly altering the public API. |
Comments suppressed due to low confidence (3)
formatter.go:10
- The identifier 'FullFormater' appears to be misspelled. Consider renaming it to 'FullFormatter' for consistency and clarity.
DefaultFormatter = FullFormater
error_test.go:1
- The removal of error_test.go may reduce test coverage for error handling functionality. Please ensure that the automatic op features are adequately tested elsewhere.
package errors
error.go:1
- Several exported functions have been removed from error.go. Verify that these removals are intentional and that any necessary functionality is properly migrated to avoid breaking the public API.
package errors
178de97 to
7165d55
Compare
xico42
reviewed
Jun 13, 2025
xico42
previously approved these changes
Jun 13, 2025
Adds Op automatically when using `errors.With`. The default value comes from go's runtime and will be something like package.funcname. If an Op was manually added the automatic Op will be skipped. For anonymous functions a line number is also added. Both the line number and automatic op can be turned off by Global variables and environment variables.
e03572d to
3cca9bf
Compare
xico42
approved these changes
Jun 16, 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.
Adds Op automatically when using
errors.With. The default value comesfrom go's runtime and will be something like package.funcname.
If an Op was manually added the automatic Op will be skipped.
For anonymous functions a line number is also added.
Both the line number and automatic op can be turned off by Global
variables and environment variables.
Example of a complete error:
main.doGreetings.func1 (line 52): main.doGreetings: main.greetings: sayHello: [fatal] (RUNTIME_ERROR) name cannot be empty {context3: value3, context2: value2, context1: value1}