-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
When multiple columns are missing, sv will create an UnexpectedEndOfRow error for each row that is missing, example:
> decode ((,) <$> int <*> int) (Identity mempty)
Failure (DecodeErrors (UnexpectedEndOfRow :| [UnexpectedEndOfRow]))Here we wanted two int fields, but the given csv had zero (mempty :: Vector s) fields, so there’s two UEOR errors.
When pretty printing, usually the user wants to know how many rows were missing.
Here is a mockup of how they can be counted:
-- Pretties DecdodeErrors, but counts all UnexpectedEndOfRow errors so we can display how many rows were missing.
prettyDecodeErrors errs =
errs
& foldMap1
( \case
Dec.UnexpectedEndOfRow -> (Sum 1, singleton Dec.UnexpectedEndOfRow)
err -> (Sum 0, singleton err)
)
& \case
(Sum 0, errs') -> errs' & fmap (prettyDecodeError 0)
(Sum n, errs') ->
errs'
& NonEmpty.nubBy (\a b -> a == Dec.UnexpectedEndOfRow && b == Dec.UnexpectedEndOfRow)
& fmap (prettyDecodeError n)
prettyDecodeError missingRows = \case
Dec.UnexpectedEndOfRow -> [fmt|"Unexpected end of line, requires more {show missingRows} more rows"|]
Dec.ExpectedEndOfRow fields -> "Extra unknown fields: " <> (fmap bytesToTextUtf8Lenient fields & show & stringToText)
Dec.MissingColumn c -> "Missing column: " <> bytesToTextUtf8Lenient c
Dec.BadDecode err -> "Decode error: " <> bytesToTextUtf8Lenient err
other -> "Unknown decode error: " <> (other & show & stringToText)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels