Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

bug in the third package sqlutils #943

@yangeagle

Description

@yangeagle

I am not sure whether this question is suitable here.

I find a problem in the third package github.com/openark/golib/sqlutils used in orchestrator.

package: github.com/openark/golib/sqlutils
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 correct 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

I also submitted an issue here.

Please check it.
cc @MOON-CLJ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions