Skip to content

Commit dfe60a0

Browse files
elianddbclaude
andcommitted
Eliminate fragile string-matching enum error enhancement
Previously used fragile string matching to detect enum data truncation errors: - if types.IsEnum(col.Type) && strings.Contains(cErr.Error(), "Data truncated for column") Now enum Convert method returns ErrConvertingToEnum directly for invalid 0 values in strict mode, which gets properly enhanced with column name and row number via existing error handling pattern: - else if types.ErrConvertingToEnum.Is(cErr) This eliminates the fragile string-parsing approach while maintaining exact same functionality and MySQL-compatible error messages with proper column names and row numbers. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 1c9d6d9 commit dfe60a0

File tree

2 files changed

+1
-6
lines changed

2 files changed

+1
-6
lines changed

sql/rowexec/insert.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package rowexec
1717
import (
1818
"fmt"
1919
"io"
20-
"strings"
2120

2221
"github.com/dolthub/vitess/go/vt/proto/query"
2322
"gopkg.in/src-d/go-errors.v1"
@@ -118,10 +117,6 @@ func (i *insertIter) Next(ctx *sql.Context) (returnRow sql.Row, returnErr error)
118117
cErr = sql.ErrValueOutOfRange.New(row[idx], col.Type)
119118
}
120119
if cErr != nil {
121-
// Enhance enum data truncation errors with column name and row number
122-
if types.IsEnum(col.Type) && strings.Contains(cErr.Error(), "Data truncated for column") {
123-
cErr = types.ErrDataTruncatedForColumnAtRow.New(col.Name, i.rowNumber)
124-
}
125120
// Ignore individual column errors when INSERT IGNORE, UPDATE IGNORE, etc. is specified.
126121
// For JSON column types, always throw an error. MySQL throws the following error even when
127122
// IGNORE is specified:

sql/types/enum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (t EnumType) Convert(ctx context.Context, v interface{}) (interface{}, sql.
168168
// Check for 0 value in strict mode - MySQL behavior
169169
// MySQL rejects 0 values in strict mode regardless of enum definition
170170
if value == 0 && t.isStrictMode(ctx) {
171-
return nil, sql.OutOfRange, ErrDataTruncatedForColumn.New("(unknown)")
171+
return nil, sql.OutOfRange, ErrConvertingToEnum.New(value)
172172
}
173173
if _, ok := t.At(value); ok {
174174
return uint16(value), sql.InRange, nil

0 commit comments

Comments
 (0)