-
Notifications
You must be signed in to change notification settings - Fork 6k
ddl: improve an error handling #5748
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
Conversation
var err *MyErr e1 := errors.Trace(err) e2 := errors.Cause(e1) e2 != nil // Isn't it beyond the normal comprehension? We should never errors.Trace(xxx) when xxx is other than error type
@@ -464,7 +464,10 @@ func (d *ddl) doDDLJob(ctx context.Context, job *model.Job) error { | |||
return nil | |||
} | |||
|
|||
return errors.Trace(historyJob.Error) | |||
if historyJob.Error != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't a good way to handle this problem.
If historyJob isn't synced, the historyJob's Error mustn't be nil. So I think something wrong with the operation of running DDL job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just change one line, where I think the error handling could be improved.
I think We should never errors.Trace(xxx) when xxx is other than error type..
Maybe I use the wrong presentation, this have nothing to do with fix, I just want to make the code more robust. So is that acceptable? @zimulala
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
I think historyJob's Error is nil is also a problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relate to #5751
/run-all-tests |
LGTM |
1 similar comment
LGTM |
/run-all-tests |
We should never errors.Trace(xxx) when xxx is other than error type.
====================== TL;DR ===============
The minimal runnable code to demonstrate the problem:
The problem is the interface conversion, if we pass a
*MyErr
type with value nil to this functionIt's returns a error interface, which is not nil with type
*MyErr
, the underlying value is nil however.This kind of data is toxic. It's easy to trap here:
So the simple rule: We should never errors.Trace(xxx) when xxx is other than error type.
B.T.W, this kind of code is also dangerous:
@coocood @shenli