11package testhelper
22
33import (
4+ "errors"
45 "fmt"
56 "math"
67 "math/bits"
78 "runtime"
89 "strconv"
910 "strings"
10-
11- "github.com/pkg/errors"
1211)
1312
1413var TestFunctionsCalled = map [string ]bool {
@@ -68,22 +67,22 @@ func Parse(value string) (Money, error) {
6867
6968 parts := strings .Split (value , "." )
7069 if len (parts ) != 2 || (len (parts [1 ]) != 2 && len (parts [1 ]) != 4 ) {
71- return Money {}, errors .Errorf ("not valid money: %s, must have 2 or 4 decimals" , value )
70+ return Money {}, fmt .Errorf ("not valid money: %s, must have 2 or 4 decimals" , value )
7271 }
7372
7473 if len (parts [0 ]) > 1 && parts [0 ][0 ] == '0' {
75- return Money {}, errors .Errorf ("not valid money: %s, cannot have leading zeros" , value )
74+ return Money {}, fmt .Errorf ("not valid money: %s, cannot have leading zeros" , value )
7675 }
7776
7877 // Note the 63 bit here. We are converting to int64 later on, which means that 63 is all
7978 // we are going to be able to report.
8079 whole , err := strconv .ParseUint (parts [0 ], 10 , 63 )
8180 if err != nil {
82- return Money {}, errors .Errorf ("not valid money: %s (parts[0]=%s)" , value , parts [0 ])
81+ return Money {}, fmt .Errorf ("not valid money: %s (parts[0]=%s)" , value , parts [0 ])
8382 }
8483 fraccent , err := strconv .ParseUint (parts [1 ], 10 , 16 )
8584 if err != nil {
86- return Money {}, errors .Errorf ("not valid money: %s (parts[1]=%s)" , value , parts [1 ])
85+ return Money {}, fmt .Errorf ("not valid money: %s (parts[1]=%s)" , value , parts [1 ])
8786 }
8887
8988 // This will never overflow, since the max we parse in fraccent is 16 bit, and we
@@ -97,12 +96,12 @@ func Parse(value string) (Money, error) {
9796
9897 hi , lo := bits .Mul64 (whole , 10000 )
9998 if hi != 0 {
100- return Money {}, errors .Errorf ("The amount %s would overflow an uint64 if converted to cents" , value )
99+ return Money {}, fmt .Errorf ("The amount %s would overflow an uint64 if converted to cents" , value )
101100 }
102101
103102 cc , carry := bits .Add64 (lo , fraccent , 0 )
104103 if carry != 0 {
105- return Money {}, errors .Errorf ("The amount %s would overflow an uint64 if converted to cents" , value )
104+ return Money {}, fmt .Errorf ("The amount %s would overflow an uint64 if converted to cents" , value )
106105 }
107106
108107 if sign == 1 {
@@ -128,11 +127,11 @@ func (target *Money) Scan(value interface{}) error {
128127 case string :
129128 strvalue = s
130129 default :
131- return errors .Errorf ("not valid money: %v" , value )
130+ return fmt .Errorf ("not valid money: %v" , value )
132131 }
133132 parsed , err := Parse (strvalue )
134133 if err != nil {
135- return errors . WithStack ( err )
134+ return err
136135 }
137136 * target = parsed
138137 return nil
0 commit comments