diff --git a/errors.go b/errors.go index aa9d190d..40b8ef66 100644 --- a/errors.go +++ b/errors.go @@ -4,28 +4,26 @@ package fincen -import "fmt" +import ( + "fmt" +) // NewErrTextLength returns an error that the length of value is invalid func NewErrValueInvalid(typeStr string) error { - errStr := fmt.Sprintf("The %s has invalid value", typeStr) - return fmt.Errorf(errStr) + return fmt.Errorf("The %s has invalid value", typeStr) } // NewErrFieldRequired returns an error when a field is required func NewErrFieldRequired(typeStr string) error { - errStr := fmt.Sprintf("The %s is a required field", typeStr) - return fmt.Errorf(errStr) + return fmt.Errorf("The %s is a required field", typeStr) } // NewErrFiledOmitted returns an error that the field should be omitted func NewErrFiledOmitted(typeStr string) error { - errStr := fmt.Sprintf("The %s should be omitted", typeStr) - return fmt.Errorf(errStr) + return fmt.Errorf("The %s should be omitted", typeStr) } // NewErrMinMaxRange returns an error that the field has min/max element range func NewErrMinMaxRange(typeStr string) error { - errStr := fmt.Sprintf("The %s has invalid min & max range", typeStr) - return fmt.Errorf(errStr) + return fmt.Errorf("The %s has invalid min & max range", typeStr) } diff --git a/utils.go b/utils.go index 449551f1..95a64bc6 100644 --- a/utils.go +++ b/utils.go @@ -35,7 +35,12 @@ func NumericStringField(s string, max uint) string { if ln > max { return s[ln-max:] } - s = strings.Repeat("0", int(max-ln)) + s + rem := max - ln + if rem > 1_000_000_000 { + return "" + } else { + s = strings.Repeat("0", int(rem)) + s + } return s }