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

the error will not return to the caller #5

Open
yangeagle opened this issue Jul 20, 2019 · 0 comments
Open

the error will not return to the caller #5

yangeagle opened this issue Jul 20, 2019 · 0 comments

Comments

@yangeagle
Copy link

yangeagle commented Jul 20, 2019

I find a problem in this repo when I use orchestrator.

file: golib/sqlutils/sqlutils.go
code:

// QueryRowsMap is a convenience function allowing querying a result set while poviding a callback
// function activated per read row.
func QueryRowsMap(db *sql.DB, query string, on_row func(RowMap) error, args ...interface{}) error {
	var err error
	defer func() {
		if derr := recover(); derr != nil {
			err = errors.New(fmt.Sprintf("QueryRowsMap unexpected error: %+v", derr))
		}
	}()

... ...
	return err
}

The err modified in defer will not return to the caller.

For example:

package main

import (
        "fmt"
)

func main(){
        i := test()
        fmt.Println("main i:", i)
}

func test() int {
        var a int
        defer func () {
                a = 2
        }()

        a = 1
        return a
}

output:
main i: 1

The right usage like this:

package main

import (
        "fmt"
)

func main(){
        i := test()
        fmt.Println("main i:", i)
}

func test() (a int) {
        defer func () {
                a = 2
        }()

        a = 1
        return a
}

output:
main i: 2

Please check it.

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

No branches or pull requests

2 participants
@yangeagle and others