Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

*: refactor error system #216

Merged
merged 72 commits into from
Aug 16, 2019
Merged

*: refactor error system #216

merged 72 commits into from
Aug 16, 2019

Conversation

amyangfei
Copy link
Contributor

@amyangfei amyangfei commented Jul 29, 2019

What problem does this PR solve?

implement error system based on RFC introduced in #211

What is changed and how it works?

  1. add new error library

  2. classify errors and use new error library for all error handling, classification is working in progress:

    • checker
    • relay unit
    • dump unit
    • load unit
    • sync unit
    • dm master
    • dm worker
    • dm pkg

Check List

Tests

  • Unit test
  • Integration test

Code changes

  • Has exported variable/fields change

Side effects

Related changes

  • Need to update the documentation
  • Need to be included in the release note

@amyangfei amyangfei added priority/important Major change, requires approval from ≥2 primary reviewers status/WIP This PR is still work in progress type/feature New feature labels Jul 29, 2019
@codecov
Copy link

codecov bot commented Jul 29, 2019

Codecov Report

Merging #216 into master will increase coverage by 0.3739%.
The diff coverage is 34.5403%.

@@               Coverage Diff                @@
##             master       #216        +/-   ##
================================================
+ Coverage   59.1362%   59.5102%   +0.3739%     
================================================
  Files           123        125         +2     
  Lines         14240      14374       +134     
================================================
+ Hits           8421       8554       +133     
- Misses         4957       4959         +2     
+ Partials        862        861         -1

@amyangfei
Copy link
Contributor Author

/run-all-tests

ClassBinlogOp: "binlog-op",
ClassCheckpoint: "checkpoint",
ClassTaskCheck: "task-check",
ClassRelayAPI: "relay-api",
Copy link
Collaborator

Choose a reason for hiding this comment

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

RelayClient?

}

// levelGeneratef is an inner interface to generate new *Error
func (e *Error) levelGeneratef(stackSkipLevel int, format string, args ...interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I unveiled its mysterious veil, then I fell into meditation

if !ok {
return errors.Annotatef(err, format, args...)
}
e.message = fmt.Sprintf("%s: %s", format, e.getMsg())
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

should it be e.message = e.message + ": " + fmt.Sprintf(fmt, args)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope, this keeps the same as errors.Annotatef we used in pingcap/errors
such as https://github.com/pingcap/errors/blob/master/format_test.go#L140-L154


// Generatef generates a new *Error with the same class and code, and a new formatted message.
func (e *Error) Generatef(format string, args ...interface{}) error {
return e.levelGeneratef(1, format, args...)
Copy link
Collaborator

Choose a reason for hiding this comment

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

discard old message directly? or make it like annotatef?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generate creates a new error with arguments while Generatef replaces the error message and arguments. They share the same error code, error status, but may have different error messages.

pkg/utils/db.go Outdated Show resolved Hide resolved
pkg/terror/error_list.go Outdated Show resolved Hide resolved
syncer/relay.go Outdated Show resolved Hide resolved
syncer/syncer.go Show resolved Hide resolved
syncer/syncer.go Outdated Show resolved Hide resolved
@amyangfei
Copy link
Contributor Author

/run-all-tests

_utils/terror_gen/gen.go Outdated Show resolved Hide resolved
_utils/terror_gen/checker_template.go Outdated Show resolved Hide resolved
Copy link
Contributor

@WangXiangUSTC WangXiangUSTC left a comment

Choose a reason for hiding this comment

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

rest LGTM

_utils/terror_gen/checker_template.go Outdated Show resolved Hide resolved
dm/worker/config.go Outdated Show resolved Hide resolved
case <-ctx.Done():
return errors.Trace(ctx.Err())
return ctx.Err()
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need add error code for context canceled or deadline?

Copy link
Contributor Author

@amyangfei amyangfei Aug 15, 2019

Choose a reason for hiding this comment

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

yep, most of the ctx.Err() are used to check context cancel or timeout and not exposed to users. I didn't wrap ctx.Err() with new error in the consideration of less code logic change. Besides ctx.Err() here is returned in a GRPC round trip, the context cancel behavior is in the client-side, maybe using a new error with call stack changes nothing. We may refine this later.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

syncer/dml.go Outdated Show resolved Hide resolved
Copy link
Member

@csuzhangxc csuzhangxc left a comment

Choose a reason for hiding this comment

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

LGTM

@csuzhangxc csuzhangxc added status/LGT1 One reviewer already commented LGTM and removed status/PTAL This PR is ready for review. Add this label back after committing new changes labels Aug 15, 2019
Copy link
Contributor

@WangXiangUSTC WangXiangUSTC left a comment

Choose a reason for hiding this comment

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

LGTM

@WangXiangUSTC WangXiangUSTC added status/LGT2 Two reviewers already commented LGTM, ready for merge and removed status/LGT1 One reviewer already commented LGTM labels Aug 16, 2019
@amyangfei amyangfei merged commit 54e18df into pingcap:master Aug 16, 2019
@amyangfei amyangfei deleted the error-system branch August 16, 2019 02:21
lichunzhu pushed a commit to lichunzhu/dm that referenced this pull request Apr 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
priority/important Major change, requires approval from ≥2 primary reviewers status/LGT2 Two reviewers already commented LGTM, ready for merge type/feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants