Skip to content

cqlr masks gocql errors when Scanning #6

@nt3rp

Description

@nt3rp

I noticed when working on a project that I wasn't getting any results from Cassandra, even though there were results in the database. My code looks like something like this:

    qs := "SELECT a, b, c FROM my_table"
    query := cqlr.BindQuery(s.Session.Query(qs))

    var object MyObject
    objects := make([]MyObject, 0)
    for query.Scan(&object) {
        objects = append(objects, object)
    }

    if err := query.Close(); err != nil {
        return objects, err
    }

    return objects, nil

Given that MyObject is special in how it is marshalled / unmarshalled, I suspected that there was some error in how I conduct that, but the above code throws no errors.

As it turns out, cqlr masks the error. On cqlr.go#L74, an error is only returned if cqlr had a problem. If there is a problem unmarshalling (as might happen in cqlr.go#L107, the error won't be caught until iter is closed... which doesn't happen.

I think that all that is needed is that in Binding.Close, it returns b.err or b.iter.Close().

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