mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-04-28 02:18:08 -05:00
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:
@@ -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{}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user