Skip to content

Commit 8cb2915

Browse files
committed
fix: AttributeSelector returns error containing unfound attribute name
1 parent 71d06ed commit 8cb2915

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

driver/driver_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ func TestSelectCamelCase(t *testing.T) {
197197
if err != nil {
198198
t.Fatalf("sql.Query CamelCase error : %s", err)
199199
}
200+
201+
_, err = db.Query(`SELECT TestCamelCase, nope, email_snake FROM account WHERE 1`)
202+
if err == nil {
203+
t.Fatalf("expected attribute not found error")
204+
}
205+
ee := "attribute not defined: account.nope"
206+
if err.Error() != ee {
207+
t.Fatalf("expected error to be '%s', got '%s'", ee, err.Error())
208+
}
200209
}
201210

202211
func TestSelectSimplePredicate(t *testing.T) {

engine/agnostic/relation.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package agnostic
22

33
import (
44
"container/list"
5-
"errors"
65
"fmt"
76
"strings"
87
"sync"
@@ -61,7 +60,7 @@ func (r *Relation) Attribute(name string) (int, Attribute, error) {
6160
name = strings.ToLower(name)
6261
index, ok := r.attrIndex[name]
6362
if !ok {
64-
return 0, Attribute{}, errors.New("attribute not defined")
63+
return 0, Attribute{}, fmt.Errorf("attribute not defined: %s.%s", r.name, name)
6564
}
6665
return index, r.attributes[index], nil
6766
}

0 commit comments

Comments
 (0)