diff --git a/amount.go b/amount.go index a15b311..e3d6de2 100644 --- a/amount.go +++ b/amount.go @@ -360,7 +360,10 @@ func (a Amount) Value() (driver.Value, error) { // Allows scanning amounts from a PostgreSQL composite type. func (a *Amount) Scan(src interface{}) error { // Wire format: "(9.99,USD)". - input := src.(string) + input, ok := src.(string) + if !ok { + return fmt.Errorf("invalid src: %v", src) + } if len(input) == 0 { return nil } diff --git a/amount_test.go b/amount_test.go index dce7e96..4cdf662 100644 --- a/amount_test.go +++ b/amount_test.go @@ -930,3 +930,11 @@ func TestAmount_Scan(t *testing.T) { }) } } + +func TestAmount_ScanNonString(t *testing.T) { + var a currency.Amount + err := a.Scan(123) + if err == nil { + t.Errorf("error expected") + } +}