Skip to content

Commit

Permalink
sql/mysql: add table+column context to parse type errors (#2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
a8m committed Aug 25, 2023
1 parent dc463ff commit 136aeab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions sql/mysql/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func FormatType(t schema.Type) (string, error) {
}
case *schema.DecimalType:
if f = strings.ToLower(t.T); f != TypeDecimal && f != TypeNumeric {
return "", fmt.Errorf("mysql: unexpected decimal type: %q", t.T)
return "", fmt.Errorf("unexpected decimal type: %q", t.T)
}
switch p, s := t.Precision, t.Scale; {
case p < 0 || s < 0:
return "", fmt.Errorf("mysql: decimal type must have precision > 0 and scale >= 0: %d, %d", p, s)
return "", fmt.Errorf("decimal type must have precision > 0 and scale >= 0: %d, %d", p, s)
case p < s:
return "", fmt.Errorf("mysql: decimal type must have precision >= scale: %d < %d", p, s)
return "", fmt.Errorf("decimal type must have precision >= scale: %d < %d", p, s)
case p == 0 && s == 0:
// The default value for precision is 10 (i.e. decimal(0,0) = decimal(10)).
p = 10
Expand Down Expand Up @@ -205,7 +205,7 @@ func ParseType(raw string) (schema.Type, error) {
// github.com/mysql/mysql-server/blob/8.0/sql/field.cc#Field_enum::sql_type
rv := strings.TrimSuffix(strings.TrimPrefix(raw, t+"("), ")")
if rv == "" {
return nil, fmt.Errorf("mysql: unexpected enum type: %q", raw)
return nil, fmt.Errorf("unexpected enum type: %q", raw)
}
values := strings.Split(rv, "','")
for i := range values {
Expand Down
2 changes: 1 addition & 1 deletion sql/mysql/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (i *inspect) addColumn(s *schema.Schema, rows *sql.Rows) error {
}
ct, err := ParseType(c.Type.Raw)
if err != nil {
return err
return fmt.Errorf("parse %q.%q type %q: %w", t.Name, c.Name, c.Type.Raw, err)
}
c.Type.Type = ct
attr, err := parseExtra(extra.String)
Expand Down

0 comments on commit 136aeab

Please sign in to comment.