mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-01 10:09:41 -06:00
add file line number to import table error message
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, tableName string, err error) (quit bool)
|
||||
type badRowFn func(row sql.Row, rowSchema sql.PrimaryKeySchema, tableName string, lineNumber int, 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, tableName string, err error) (quit bool) {
|
||||
badRowCB := func(row sql.Row, rowSchema sql.PrimaryKeySchema, tableName string, lineNumber int, 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 inserting into table %s:\n%s", tableName, formattedSqlRow)
|
||||
rowErr = fmt.Errorf("A bad row was encountered inserting into table %s (on line %d):\n%s", tableName, lineNumber, formattedSqlRow)
|
||||
if wie, ok := err.(sql.WrappedInsertError); ok {
|
||||
if e, ok := wie.Cause.(*errors.Error); ok {
|
||||
if ue, ok := e.Cause().(sql.UniqueKeyError); ok {
|
||||
@@ -616,15 +616,18 @@ func moveRows(
|
||||
return err
|
||||
}
|
||||
|
||||
line := 1
|
||||
|
||||
for {
|
||||
sqlRow, err := rd.ReadSqlRow(ctx)
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
line += 1
|
||||
|
||||
if err != nil {
|
||||
if table.IsBadRow(err) {
|
||||
quit := badRowCb(sqlRow, rdSqlSch, options.destTableName, err)
|
||||
quit := badRowCb(sqlRow, rdSqlSch, options.destTableName, line, 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, tableName string, 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, lineNumber int, err error) bool) (err error) {
|
||||
err = s.forceDropTableIfNeeded()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -190,6 +190,8 @@ func (s *SqlEngineTableWriter) WriteRows(ctx context.Context, inputChannel chan
|
||||
}
|
||||
}()
|
||||
|
||||
line := 1
|
||||
|
||||
for {
|
||||
if s.statsCB != nil && atomic.LoadInt32(&s.statOps) >= tableWriterStatUpdateRate {
|
||||
atomic.StoreInt32(&s.statOps, 0)
|
||||
@@ -197,6 +199,7 @@ func (s *SqlEngineTableWriter) WriteRows(ctx context.Context, inputChannel chan
|
||||
}
|
||||
|
||||
row, err := iter.Next(s.sqlCtx)
|
||||
line += 1
|
||||
|
||||
// All other errors are handled by the errorHandler
|
||||
if err == nil {
|
||||
@@ -219,7 +222,7 @@ func (s *SqlEngineTableWriter) WriteRows(ctx context.Context, inputChannel chan
|
||||
offendingRow = n.OffendingRow
|
||||
}
|
||||
|
||||
quit := badRowCb(offendingRow, s.tableSchema, s.tableName, err)
|
||||
quit := badRowCb(offendingRow, s.tableSchema, s.tableName, line, err)
|
||||
if quit {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ 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 inserting into table shirts:" ]] || false # table name
|
||||
[[ "$output" =~ "A bad row was encountered inserting into table shirts (on line 3):" ]] || false # table name
|
||||
[[ "$output" =~ "name: shirt2" ]] || false # column names
|
||||
[[ "$output" =~ "size: other" ]] || false
|
||||
[[ "$output" =~ "color: green" ]] || false
|
||||
|
||||
Reference in New Issue
Block a user