Skip to content

feat: automatic op#4

Merged
rjfonseca merged 2 commits into
mainfrom
feat/automatic-op
Jun 16, 2025
Merged

feat: automatic op#4
rjfonseca merged 2 commits into
mainfrom
feat/automatic-op

Conversation

@rjfonseca
Copy link
Copy Markdown
Member

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.

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}

Copilot AI review requested due to automatic review settings June 12, 2025 13:38
@rjfonseca rjfonseca requested a review from xico42 as a code owner June 12, 2025 13:38
@rjfonseca rjfonseca self-assigned this Jun 12, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@rjfonseca rjfonseca force-pushed the feat/automatic-op branch 2 times, most recently from 178de97 to 7165d55 Compare June 12, 2025 18:05
Comment thread with.go Outdated
xico42
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.
@rjfonseca rjfonseca force-pushed the feat/automatic-op branch from e03572d to 3cca9bf Compare June 16, 2025 14:07
@rjfonseca rjfonseca merged commit cb60899 into main Jun 16, 2025
3 checks passed
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.

3 participants