Skip to content

Commit

Permalink
Improve has_many "missing field" error message (#480)
Browse files Browse the repository at this point in the history
This patch adds more context to an error that can occur when the target field of a has_many association does not exist on the struct. Before this patch, an error message would look like this:

```
could not set '467cc7fa-d2f9-4ea7-b943-4dee7f4bddf9' in '<invalid reflect.Value>'
```

After the patch, it looks like this:

```
could not set field 'RequestID' in table 'selfservice_login_request_methods' to value '110540dc-e8cc-4587-b391-3114c75c012b' for 'has_many' relation
```

Signed-off-by: aeneasr <[email protected]>
  • Loading branch information
aeneasr authored and stanislas-m committed Nov 30, 2019
1 parent 91c1962 commit 6e21180
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion associations/has_many_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (a *hasManyAssociation) AfterSetup() error {
fval.Set(reflect.ValueOf(ownerID))
}
} else {
return fmt.Errorf("could not set '%s' in '%s'", ownerID, fval)
return fmt.Errorf("could not set field '%s' in table '%s' to value '%s' for 'has_many' relation", a.ownerName+"ID", a.tableName, ownerID)
}
}
return nil
Expand Down

0 comments on commit 6e21180

Please sign in to comment.