mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-07 10:18:44 -06:00
add table name to import table error
This commit is contained in:
@@ -513,7 +513,7 @@ func newImportSqlEngineMover(ctx context.Context, dEnv *env.DoltEnv, rdSchema sc
|
||||
return mv, nil
|
||||
}
|
||||
|
||||
type badRowFn func(row sql.Row, rowSchema sql.PrimaryKeySchema, err error) (quit bool)
|
||||
type badRowFn func(row sql.Row, rowSchema sql.PrimaryKeySchema, tableName string, err error) (quit bool)
|
||||
|
||||
func move(ctx context.Context, rd table.SqlRowReader, wr *mvdata.SqlEngineTableWriter, options *importOptions) (int64, error) {
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
@@ -524,7 +524,7 @@ func move(ctx context.Context, rd table.SqlRowReader, wr *mvdata.SqlEngineTableW
|
||||
var printBadRowsStarted bool
|
||||
var badCount int64
|
||||
|
||||
badRowCB := func(row sql.Row, rowSchema sql.PrimaryKeySchema, err error) (quit bool) {
|
||||
badRowCB := func(row sql.Row, rowSchema sql.PrimaryKeySchema, tableName string, err error) (quit bool) {
|
||||
// record the first error encountered unless asked to ignore it
|
||||
if row != nil && rowErr == nil && !options.contOnErr {
|
||||
var sqlRowWithColumns []string
|
||||
@@ -533,7 +533,7 @@ func move(ctx context.Context, rd table.SqlRowReader, wr *mvdata.SqlEngineTableW
|
||||
}
|
||||
formattedSqlRow := strings.Join(sqlRowWithColumns, "")
|
||||
|
||||
rowErr = fmt.Errorf("A bad row was encountered\n%s", formattedSqlRow)
|
||||
rowErr = fmt.Errorf("A bad row was encountered inserting into table %s:\n%s", tableName, formattedSqlRow)
|
||||
if wie, ok := err.(sql.WrappedInsertError); ok {
|
||||
if e, ok := wie.Cause.(*errors.Error); ok {
|
||||
if ue, ok := e.Cause().(sql.UniqueKeyError); ok {
|
||||
@@ -624,7 +624,7 @@ func moveRows(
|
||||
|
||||
if err != nil {
|
||||
if table.IsBadRow(err) {
|
||||
quit := badRowCb(sqlRow, rdSqlSch, err)
|
||||
quit := badRowCb(sqlRow, rdSqlSch, options.destTableName, err)
|
||||
if quit {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func NewSqlEngineTableWriter(ctx context.Context, dEnv *env.DoltEnv, createTable
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *SqlEngineTableWriter) WriteRows(ctx context.Context, inputChannel chan sql.Row, badRowCb func(row sql.Row, rowSchema sql.PrimaryKeySchema, err error) bool) (err error) {
|
||||
func (s *SqlEngineTableWriter) WriteRows(ctx context.Context, inputChannel chan sql.Row, badRowCb func(row sql.Row, rowSchema sql.PrimaryKeySchema, tableName string, err error) bool) (err error) {
|
||||
err = s.forceDropTableIfNeeded()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -219,7 +219,7 @@ func (s *SqlEngineTableWriter) WriteRows(ctx context.Context, inputChannel chan
|
||||
offendingRow = n.OffendingRow
|
||||
}
|
||||
|
||||
quit := badRowCb(offendingRow, s.tableSchema, err)
|
||||
quit := badRowCb(offendingRow, s.tableSchema, s.tableName, err)
|
||||
if quit {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ CSV
|
||||
[ "${#lines[@]}" -eq 6 ]
|
||||
}
|
||||
|
||||
@test "import-append-tables: import error message lists columns with row" {
|
||||
@test "import-append-tables: import error message contains useful information" {
|
||||
dolt sql -q "CREATE TABLE shirts (name VARCHAR(40), size ENUM('x-small', 'small', 'medium', 'large', 'x-large'), color ENUM('red', 'blue'));"
|
||||
run dolt table import -a shirts <<CSV
|
||||
name, size, color
|
||||
@@ -112,8 +112,8 @@ CSV
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "An error occurred while moving data" ]] || false
|
||||
[[ "$output" =~ "cause: value other is not valid for this Enum" ]] || false
|
||||
[[ "$output" =~ "A bad row was encountered" ]] || false
|
||||
[[ "$output" =~ "name: shirt2" ]] || false
|
||||
[[ "$output" =~ "A bad row was encountered inserting into table shirts:" ]] || false # table name
|
||||
[[ "$output" =~ "name: shirt2" ]] || false # column names
|
||||
[[ "$output" =~ "size: other" ]] || false
|
||||
[[ "$output" =~ "color: green" ]] || false
|
||||
[[ "$output" =~ "Errors during import can be ignored using '--continue'" ]] || false
|
||||
|
||||
Reference in New Issue
Block a user