diff --git a/dhall-csv/src/Dhall/CsvToDhall.hs b/dhall-csv/src/Dhall/CsvToDhall.hs index 3a71ea2e9..5dab35f34 100644 --- a/dhall-csv/src/Dhall/CsvToDhall.hs +++ b/dhall-csv/src/Dhall/CsvToDhall.hs @@ -159,6 +159,7 @@ import Prettyprinter (Pretty) import qualified Data.Csv import qualified Data.HashMap.Strict as HashMap +import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Sequence as Sequence import qualified Data.Text import qualified Dhall.Core as Core @@ -273,7 +274,7 @@ dhallFromCsv Conversion{..} typeExpr = listConvert (Core.normalize typeExpr) recordConvert (Core.Record record) csvRecord | badKeys <- lefts (map decodeUtf8' (HashMap.keys csvRecord)) , not (null badKeys) - = Left $ UnicodeError (head badKeys) -- Only report first key that failed to be decoded + = Left $ UnicodeError (NonEmpty.head . NonEmpty.fromList $ badKeys) -- Only report first key that failed to be decoded | extraKeys <- (map decodeUtf8 $ HashMap.keys csvRecord) \\ Map.keys record , strictRecs && not (null extraKeys) = Left $ UnhandledFields extraKeys diff --git a/dhall-docs/src/Dhall/Docs/CodeRenderer.hs b/dhall-docs/src/Dhall/Docs/CodeRenderer.hs index 51224bb64..29841c660 100644 --- a/dhall-docs/src/Dhall/Docs/CodeRenderer.hs +++ b/dhall-docs/src/Dhall/Docs/CodeRenderer.hs @@ -56,6 +56,7 @@ import Text.Megaparsec.Pos (SourcePos (..)) import qualified Control.Monad.Trans.Writer.Strict as Writer import qualified Data.List +import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Maybe as Maybe import qualified Data.Set as Set import qualified Data.Text as Text @@ -374,7 +375,7 @@ renderCodeWithHyperLinks contents expr = pre_ $ go (1, 1) lines_ imports -- calls to `head` and `last` here should never fail since `importLines` -- have at least one element - let (firstImportLine, lastImportLine) = (head importLines, last importLines) + let (firstImportLine, lastImportLine) = (NonEmpty.head . NonEmpty.fromList $ importLines, last importLines) let prefixCols = Text.take (importStartCol - currCol) firstImportLine let suffixCols = Text.drop (importEndCol - currCol) lastImportLine diff --git a/dhall-docs/src/Dhall/Docs/Comment.hs b/dhall-docs/src/Dhall/Docs/Comment.hs index 7bab3889c..9acb085d3 100644 --- a/dhall-docs/src/Dhall/Docs/Comment.hs +++ b/dhall-docs/src/Dhall/Docs/Comment.hs @@ -189,7 +189,7 @@ parseDhallDocsText (BlockComment blockComment) = Just e -> DhallDocsText e where joinedText = Data.Text.strip $ Data.Text.unlines reIndentedLines - commentLines = tail $ Data.Text.lines blockComment + commentLines = NonEmpty.tail $ NonEmpty.fromList $ Data.Text.lines blockComment leadingSpaces = Data.Text.takeWhile isSpace where diff --git a/dhall-openapi/src/Dhall/Kubernetes/Convert.hs b/dhall-openapi/src/Dhall/Kubernetes/Convert.hs index 92fb0f6fb..3f32cb52a 100644 --- a/dhall-openapi/src/Dhall/Kubernetes/Convert.hs +++ b/dhall-openapi/src/Dhall/Kubernetes/Convert.hs @@ -22,15 +22,16 @@ import Data.Text (Text) import Dhall.Kubernetes.Types import GHC.Generics (Generic, Rep) -import qualified Data.Char as Char -import qualified Data.List as List -import qualified Data.Map.Strict as Data.Map -import qualified Data.Maybe as Maybe -import qualified Data.Set as Set -import qualified Data.Sort as Sort -import qualified Data.Text as Text -import qualified Data.Tuple as Tuple -import qualified Dhall.Core as Dhall +import qualified Data.Char as Char +import qualified Data.List as List +import qualified Data.List.NonEmpty as NonEmpty +import qualified Data.Map.Strict as Data.Map +import qualified Data.Maybe as Maybe +import qualified Data.Set as Set +import qualified Data.Sort as Sort +import qualified Data.Text as Text +import qualified Data.Tuple as Tuple +import qualified Dhall.Core as Dhall import qualified Dhall.Map import qualified Dhall.Optics import qualified Data.Map as Map @@ -112,7 +113,7 @@ mkImport :: Data.Map.Map Prefix Dhall.Import -> [Text] -> Text -> Dhall.Import mkImport prefixMap components file = case Data.Map.toList filteredPrefixMap of [] -> localImport - xs -> (snd . head $ Sort.sortOn (Text.length . fst) xs) <> localImport + xs -> (snd . NonEmpty.head . NonEmpty.fromList $ Sort.sortOn (Text.length . fst) xs) <> localImport where localImport = Dhall.Import{..} importMode = Dhall.Code @@ -206,7 +207,7 @@ toTypes' prefixMap typeSplitter preferNaturalInt natIntExceptions definitions to case hierarchy of [] -> "" [ModelName{..}] -> Text.unpack (last $ Text.splitOn "." unModelName) - _ -> getModelName (tail hierarchy) + _ -> getModelName (NonEmpty.tail . NonEmpty.fromList $ hierarchy) convertAndAccumWithKey :: ModelHierarchy -> Data.Map.Map ModelName Definition -> ModelName -> Definition -> (Data.Map.Map ModelName Definition, Expr) convertAndAccumWithKey modelHierarchy accDefs k v = (mergeNoConflicts equalsIgnoringDescription accDefs leftOverDefs, expr) diff --git a/dhall-openapi/src/Dhall/Kubernetes/Types.hs b/dhall-openapi/src/Dhall/Kubernetes/Types.hs index 8bde4132b..1a38c01af 100644 --- a/dhall-openapi/src/Dhall/Kubernetes/Types.hs +++ b/dhall-openapi/src/Dhall/Kubernetes/Types.hs @@ -105,10 +105,14 @@ data BaseData = BaseData } deriving (Generic, Show, Eq) instance FromJSON BaseData where - parseJSON = withArray "array of values" $ \arr -> withObject "baseData" (\o -> do - group <- o .:? "group" .!= "" - kind <- o .: "kind" - version <- o .: "version" - let apiVersion = (if Text.null group then "" else group <> "/") <> version - pure BaseData{..}) - (head $ Vector.toList arr) + parseJSON = withArray "array of values" $ \arr -> do + case Vector.toList arr of + [] -> fail "missing baseData object in array" + (item:_) -> + withObject "baseData" (\o -> do + group <- o .:? "group" .!= "" + kind <- o .: "kind" + version <- o .: "version" + let apiVersion = (if Text.null group then "" else group <> "/") <> version + pure BaseData{..}) + item