fix(migration): propagate specific CSV parse errors

Previously all parseCSV errors were mapped to ErrNotACSVFile, hiding
the actual cause. Now ErrFileIsEmpty is propagated correctly instead
of being misreported as an invalid CSV file.
This commit is contained in:
kolaente 2026-03-05 11:22:11 +01:00
parent 5317a87d90
commit 2b076cb7f7
1 changed files with 12 additions and 0 deletions

View File

@ -336,6 +336,10 @@ func DetectCSVStructure(file io.ReaderAt, size int64) (*DetectionResult, error)
// Parse CSV
headers, rows, err := parseCSV(data, delimiter, quoteChar)
if err != nil {
var emptyErr *migration.ErrFileIsEmpty
if errors.As(err, &emptyErr) {
return nil, err
}
return nil, &migration.ErrNotACSVFile{}
}
@ -389,6 +393,10 @@ func PreviewImport(file io.ReaderAt, size int64, config ImportConfig) (*PreviewR
_, rows, err := parseCSV(data, config.Delimiter, config.QuoteChar)
if err != nil {
var emptyErr *migration.ErrFileIsEmpty
if errors.As(err, &emptyErr) {
return nil, err
}
return nil, &migration.ErrNotACSVFile{}
}
@ -554,6 +562,10 @@ func MigrateWithConfig(u *user.User, file io.ReaderAt, size int64, config Import
_, rows, err := parseCSV(data, config.Delimiter, config.QuoteChar)
if err != nil {
var emptyErr *migration.ErrFileIsEmpty
if errors.As(err, &emptyErr) {
return err
}
return &migration.ErrNotACSVFile{}
}