Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error cause for statck trace #1910

Merged
merged 10 commits into from Apr 10, 2022
Merged

feat: add error cause for statck trace #1910

merged 10 commits into from Apr 10, 2022

Conversation

tonybase
Copy link
Member

@tonybase tonybase commented Apr 2, 2022

if err := TODO(v); err != nil {
    return errors.BadRequest(reason, message).WithCause(cause)
}

if errors.Is(err, cause) {
    // TODO
}
if cause := new(MyError); errors.As(err, &cause) {
    // TODO
}

@tonybase tonybase changed the title add error cause for statck trace feat(errors): add error cause for statck trace Apr 2, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2022

Codecov Report

Merging #1910 (b566ce4) into main (558ef4e) will decrease coverage by 0.10%.
The diff coverage is 93.93%.

@@            Coverage Diff             @@
##             main    #1910      +/-   ##
==========================================
- Coverage   80.85%   80.75%   -0.11%     
==========================================
  Files          80       81       +1     
  Lines        3573     3606      +33     
==========================================
+ Hits         2889     2912      +23     
- Misses        477      487      +10     
  Partials      207      207              
Impacted Files Coverage Δ
transport/http/status/status.go 100.00% <ø> (ø)
errors/errors.go 94.44% <93.54%> (-1.79%) ⬇️
middleware/validate/validate.go 100.00% <100.00%> (ø)
transport/http/client.go 78.88% <100.00%> (ø)
transport/grpc/codec.go 28.57% <0.00%> (ø)
transport/http/router.go 100.00% <0.00%> (+4.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 558ef4e...b566ce4. Read the comment docs.

@tonybase tonybase changed the title feat(errors): add error cause for statck trace feat: add error cause for statck trace Apr 2, 2022
daemon365
daemon365 previously approved these changes Apr 8, 2022
@tonybase tonybase merged commit a72fc68 into main Apr 10, 2022
@tonybase tonybase deleted the add-error-cause branch April 10, 2022 08:15
tonybase added a commit that referenced this pull request May 31, 2022
* add error cause for statck trace
@LL1024LL
Copy link

return fmt.Sprintf("error: code = %d reason = %s message = %s metadata = %v cause = %v", e.Code, e.Reason, e.Message, e.Metadata, e.cause)
请问为何不使用cause = %+v?
实际使用过程中发现,errors.WithStack的堆栈信息没打印出来

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.

None yet

4 participants