Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

fix returned error values in defer functions #946

Merged
merged 9 commits into from
Jan 12, 2020
Merged

Conversation

shlomi-noach
Copy link
Collaborator

Fixes #943 (and more scenarios like the one reported).

An err was not correctly returned when modified by a defer function in sqlutils.go.

Copy link

@zmoazeni zmoazeni left a comment

Choose a reason for hiding this comment

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

Hah. I was going through and creating a PR for this by adding a test file to the original repo. Beat me to the punch.

defer func() {
if derr := recover(); derr != nil {
err = errors.New(fmt.Sprintf("execInternal unexpected error: %+v", derr))
}
}()

stmt, err := db.Prepare(query)
var stmt *sql.Stmt
Copy link

Choose a reason for hiding this comment

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

Oh you do have a spacing issue here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Huh. I wonder how this passed CI? CI checks diff vs. gofmt-ed code.

zmoazeni added a commit to zmoazeni/gh-ost that referenced this pull request Aug 5, 2019
This is copied from openark/orchestrator#946 with
a slight tweak to the an indent.

Originates from the PR openark/orchestrator#943
that applies to this codebase too.

When we define the variable and attempt to set it in a defer function,
the value we're returning isn't what we expect.

Instead we can name the return values as variables and set that instead.
@shlomi-noach
Copy link
Collaborator Author

shlomi-noach commented Aug 5, 2019

adding a test file to the original repo

@zmoazeni please do

@shlomi-noach
Copy link
Collaborator Author

Sorry about the delay; I expect to look into & merge a bunch of community PRs during the first two weeks of October.

@zmoazeni
Copy link

All good @shlomi-noach. I've been super busy on my side too. Haven't done anything in OSS-land lately.

@shlomi-noach shlomi-noach temporarily deployed to production/mysql_cluster=concertmaster January 9, 2020 07:11 Inactive
@shlomi-noach shlomi-noach temporarily deployed to production/mysql_cluster=conductor January 9, 2020 07:18 Inactive
@shlomi-noach shlomi-noach deployed to production/mysql_cluster=conductor January 12, 2020 05:36 Active
@shlomi-noach shlomi-noach merged commit 831d3a2 into master Jan 12, 2020
@shlomi-noach shlomi-noach deleted the fix-sqlutils-err branch January 12, 2020 14:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug in the third package sqlutils
3 participants