Skip to content

Comments

feat: print type when empty; add fundamental type#4

Merged
youthlin merged 3 commits intomainfrom
feat/print-type-when-empty
Feb 6, 2024
Merged

feat: print type when empty; add fundamental type#4
youthlin merged 3 commits intomainfrom
feat/print-type-when-empty

Conversation

@youthlin
Copy link
Contributor

@youthlin youthlin commented Feb 6, 2024

  • errors.New and errors.Errorf(when args not contains error type) now returns *errors.fundamental
  • when a wrap error do not add any additional message, then print it's type in detail mode
type Err struct {
	err error
	foo string
}

func newErr(err error) error { return &Err{err: err, foo: "foo"} }
func (e *Err) Error() string { return e.err.Error() }
func (e *Err) Unwrap() error { return e.err }

func TestEmpty(t *testing.T) {
	err := errors.Errorf("newErr") // Line 50
	err = newErr(err)
	fmt.Printf("err=%+v\n", errors.Wrapf(err, "prefix")) // Line 52
}

Output:
// note the (3) and (4) error

err=prefix: newErr
(1) attached stack trace
 │ -- stack trace:
 │ code.gopub.tech/errors_test.TestEmpty
 │ 	/go/src/code.gopub.tech/errors/format_test.go:52
 │ [...repeated from below...]
Next: (2) prefix
Next: (3) *errors_test.Err
Next: (4) newErr
 │  -- stack trace:
 │  code.gopub.tech/errors_test.TestEmpty
 │  	/go/src/code.gopub.tech/errors/format_test.go:50
 │  testing.tRunner
 │  	/sdk/go1.21.6/src/testing/testing.go:1595
 │  runtime.goexit
 └─ 	/sdk/go1.21.6/src/runtime/asm_amd64.s:1650
Error types: (1) *errors.withStack (2) *errors.withPrefix (3) *errors_test.Err (4) *errors.fundamental

@codecov
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (430e6a0) 61.01% compared to head (1c53ea8) 62.55%.

Files Patch % Lines
format.go 63.63% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #4      +/-   ##
==========================================
+ Coverage   61.01%   62.55%   +1.54%     
==========================================
  Files          12       13       +1     
  Lines        1126     1151      +25     
==========================================
+ Hits          687      720      +33     
+ Misses        407      398       -9     
- Partials       32       33       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@youthlin youthlin merged commit 908f31c into main Feb 6, 2024
@youthlin youthlin deleted the feat/print-type-when-empty branch February 6, 2024 03:06
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.

1 participant