-
Notifications
You must be signed in to change notification settings - Fork 137
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
Fix hardware not found response #365
Fix hardware not found response #365
Conversation
Codecov Report
@@ Coverage Diff @@
## master #365 +/- ##
=======================================
Coverage 24.74% 24.74%
=======================================
Files 14 14
Lines 1277 1277
=======================================
Hits 316 316
Misses 940 940
Partials 21 21
Continue to review full report at Codecov.
|
ff43d32
to
1de2a45
Compare
db/db.go
Outdated
err = errors.Wrap(err, "SELECT") | ||
if err != nil { | ||
if err == sql.ErrNoRows { | ||
return "", err // if sql.ErrNoRows, return error as is |
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.
we should wrap this error
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.
oops i missed this comment. The reason I didn't wrap this error was because sql.ErrNoRows
is checked here:
Line 112 in 71a1c33
if err == sql.ErrNoRows { |
If I wrap the error, it becomes harder to check (unless you have any suggestions).
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.
ah true, that line should actually do if err.Cause() == sql.ErrNoRows {
then.
db/workflow.go
Outdated
@@ -108,7 +108,7 @@ func insertActionList(ctx context.Context, db *sql.DB, yamlData string, id uuid. | |||
} | |||
|
|||
workerID, err := getWorkerID(ctx, db, task.WorkerAddr) | |||
if err != nil { | |||
if err != nil && err != sql.ErrNoRows { |
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.
Can you clear up why its ok to not return an error when err == sql.ErrNoRows, its not immediately obvious to me.
On second thought why don't we return an error in that case?
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.
oh sorry it's because workerID == ""
is basically the same as sql.ErrNoRows
in this case. But I realize it's a better idea to switch the order of the check so it checks for ErrNoRows first and then any other error.
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.
ah yes I see. Yeah lets handle ErrNoRows first&explicitly so its clearer :D 👍
71a1c33
to
d82eefd
Compare
@@ -49,7 +49,7 @@ func (d TinkDB) CreateTemplate(ctx context.Context, name string, data string, id | |||
func (d TinkDB) GetTemplate(ctx context.Context, fields map[string]string) (string, string, string, error) { | |||
getCondition, err := buildGetCondition(fields) | |||
if err != nil { | |||
return "", "", "", errors.Wrap(err, "failed to build get condition") | |||
return "", "", "", errors.Wrap(err, "failed to get template") |
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.
this should actually be errors.WithMessage
not wrap but we don't need to change that now. Using errors.Wrap on an already Wrapped error will show up with a new stack trace for each Wrap
which isn't really what we want. WithMessage
just adds more messages to the original stack trace.
db/workflow.go
Outdated
@@ -109,9 +109,10 @@ func insertActionList(ctx context.Context, db *sql.DB, yamlData string, id uuid. | |||
|
|||
workerID, err := getWorkerID(ctx, db, task.WorkerAddr) | |||
if err != nil { | |||
if err == sql.ErrNoRows { |
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.
this should be if errors.Cause(err) == sql.ErrNoRows {
right?
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.
Right... I put the check for errors.Cause somewhere else.. mistakenly 🤦♀️
db/db.go
Outdated
return "", errors.Wrap(func() error { | ||
return func() error { | ||
return err | ||
}() | ||
}(), "hardware not found") |
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.
what is going on here? :D. Why isn't this just return "", errors.Wrap(err, "hardware not found")
?
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.
This is implementing the method for the Cause
to work, basically making the sql.ErrNoRows
error the "cause"
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.
Should I just create a global var HardwareNotFound
and then check for that instead?
0d31a6b
to
09e19c1
Compare
Signed-off-by: Kelly Deng <[email protected]>
43d0527
to
4aab209
Compare
db/workflow.go
Outdated
@@ -109,9 +109,10 @@ func insertActionList(ctx context.Context, db *sql.DB, yamlData string, id uuid. | |||
|
|||
workerID, err := getWorkerID(ctx, db, task.WorkerAddr) | |||
if err != nil { | |||
if errors.Cause(err) == sql.ErrNoRows { | |||
return fmt.Errorf("hardware mentioned with reference %s not found", task.WorkerAddr) |
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.
why not `errors.WithMessage() here instead of dropping the stack frame and all the goodness from errors.Wrap?
…own desc = unexpected end of JSON input' error Signed-off-by: Kelly Deng <[email protected]>
bae07fb
to
14c327f
Compare
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.
one last change and we're done!
db/workflow.go
Outdated
return get(ctx, db, query, arg) | ||
id, err := get(ctx, db, query, arg) | ||
if errors.Cause(err) == sql.ErrNoRows { | ||
err = errors.WithMessagef(errors.New(mac), "mac") |
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.
errors.WithMessage
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.
oops
Signed-off-by: Kelly Deng <[email protected]>
Signed-off-by: Kelly Deng <[email protected]>
14c327f
to
99800d5
Compare
Description
When getting hardware and hardware is not found, the error
unexpected end of JSON input
is no longer returned.The error returned will be a
hardware not found: sql: no rows in result set
instead.In addition, the error message received when trying to create a workflow with a worker/hardware not present in the database is now:
Why is this needed
The error message was vague and misleading.
Error message before (as seen in boots):
Error message after:
(I know, sorry for the bad formatting)
How Has This Been Tested?
Manually
How are existing users impacted? What migration steps/scripts do we need?
N/A
Checklist:
I have: