@@ -555,7 +555,7 @@ instance ( FromPair (a :+: b)
555555
556556parseAllNullarySum :: SumFromString f => Options -> Value -> Parser (f a)
557557parseAllNullarySum opts = withText "Text" $ \key ->
558− maybe (notFound $ unpack key) return $
558+ maybe (notFound key) return $
559559 parseSumFromString opts key
560560
561561class SumFromString f where
@@ -582,13 +582,13 @@ parseNonAllNullarySum opts =
582582 TaggedObject{..} ->
583583 withObject "Object" $ \obj -> do
584584 tag <- obj .: pack tagFieldName
585− fromMaybe (notFound $ unpack tag) $
585+ fromMaybe (notFound tag) $
586586 parseFromTaggedObject opts contentsFieldName obj tag
587587
588588 ObjectWithSingleField ->
589589 withObject "Object" $ \obj ->
590590 case H.toList obj of
591− [pair@(tag, _)] -> fromMaybe (notFound $ unpack tag) $
591+ [pair@(tag, _)] -> fromMaybe (notFound tag) $
592592 parsePair opts pair
593593 _ -> fail "Object doesn't have a single field"
594594
@@ -596,7 +596,7 @@ parseNonAllNullarySum opts =
596596 withArray "Array" $ \arr ->
597597 if V.length arr == 2
598598 then case V.unsafeIndex arr 0 of
599− String tag -> fromMaybe (notFound $ unpack tag) $
599+ String tag -> fromMaybe (notFound tag) $
600600 parsePair opts (tag, V.unsafeIndex arr 1)
601601 _ -> fail "First element is not a String"
602602 else fail "Array doesn't have 2 elements"
@@ -690,12 +690,11 @@ instance (FromRecord a, FromRecord b) => FromRecord (a :*: b) where
690690 <*> parseRecord opts Nothing obj
691691
692692instance (Selector s, GFromJSON a) => FromRecord (S1 s a) where
693− parseRecord opts (Just lab) = maybe (notFound $ unpack lab)
694− (gParseJSON opts) . H.lookup lab
695− parseRecord opts Nothing = maybe (notFound label)
696− (gParseJSON opts) . H.lookup (pack label)
693+ parseRecord opts lab = (<?> Key label) . gParseJSON opts <=< (.: label)
697694 where
698− label = fieldLabelModifier opts $ selName (undefined :: t s a p)
695+ label = fromMaybe defLabel lab
696+ defLabel = pack . fieldLabelModifier opts $
697+ selName (undefined :: t s a p)
699698
700699instance OVERLAPPING_ (Selector s, FromJSON a) =>
701700 FromRecord (S1 s (K1 i (Maybe a))) where
@@ -803,6 +802,6 @@ newtype Tagged2 (s :: * -> *) b = Tagged2 {unTagged2 :: b}
803802
804803--------------------------------------------------------------------------------
805804
806−notFound :: String -> Parser a
807−notFound key = fail $ "The key \"" ++ key ++ "\" was not found"
805+notFound :: Text -> Parser a
806+notFound key = fail $ "The key \"" ++ unpack key ++ "\" was not found"
808807{-# INLINE notFound #-}