From 904de577261e7024373e7a42fd763184764238f9 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Tue, 10 Oct 2023 13:15:59 -0400 Subject: Don't swallow namespace-parsing errors Previously, if there was a problem with the inputs and bild failed to determine the namespace, 'fromPath' would return 'Nothing' and then 'catMaybes' would drop the error-causing input altogether. In the one time that I had a bad input, this made debugging incredibly difficult. It's always a bad idea to swallow errors silently, so instead lets just kill the program if we have bad inputs. --- Biz/Namespace.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Biz/Namespace.hs') diff --git a/Biz/Namespace.hs b/Biz/Namespace.hs index 48f6277..bd283a6 100644 --- a/Biz/Namespace.hs +++ b/Biz/Namespace.hs @@ -31,9 +31,11 @@ import qualified Data.Text as Text import qualified Text.Regex.Applicative as Regex data Ext - = C + = Bash + | C | Css | Hs + | Html | Json | Keys | Lisp @@ -44,6 +46,7 @@ data Ext | Rs | Scm | Sh + | Toml deriving (Eq, Show, Generic, Aeson.ToJSON, Ord) data Namespace = Namespace {path :: [String], ext :: Ext} @@ -65,9 +68,11 @@ toPath (Namespace parts ext) = toExt :: Ext -> String toExt = ("." <>) <. \case + Bash -> "bash" C -> "c" Css -> "css" Hs -> "hs" + Html -> "html" Json -> "json" Keys -> "pub" Lisp -> "lisp" @@ -78,6 +83,7 @@ toExt = Rs -> "rs" Scm -> "scm" Sh -> "sh" + Toml -> "toml" fromHaskellContent :: String -> Maybe Namespace fromHaskellContent c = case Regex.findFirstInfix haskellModule c of @@ -95,6 +101,7 @@ toModule (Namespace parts Py) = joinWith "." parts toModule (Namespace parts Scm) = "(" ++ joinWith " " parts ++ ")" toModule (Namespace parts Rs) = joinWith "::" parts toModule (Namespace parts C) = joinWith "/" parts <> ".c" +toModule (Namespace parts Nix) = joinWith "/" parts <> ".nix" toModule (Namespace {..}) = panic <| "toModule not implemented for " <> show ext toHaskellModule :: Namespace -> String @@ -115,7 +122,10 @@ dot = Regex.some <| Regex.sym '.' name :: Regex.RE Char String name = Regex.many (Regex.psym Char.isUpper) - <> Regex.many (Regex.psym (\c -> Char.isAlphaNum c || (c == '_'))) + <> ( Regex.many + <| Regex.psym + <| \c -> Char.isAlphaNum c || c == '_' || c == '-' + ) rePath :: Regex.RE Char [String] rePath = Regex.many (name <* Regex.string "/" <|> name) @@ -125,6 +135,7 @@ reExt = C <$ Regex.string "c" <|> Css <$ Regex.string "css" <|> Hs <$ Regex.string "hs" + <|> Html <$ Regex.string "html" <|> Json <$ Regex.string "json" <|> Keys <$ Regex.string "pub" <|> Lisp <$ Regex.string "lisp" @@ -134,6 +145,8 @@ reExt = <|> Rs <$ Regex.string "rs" <|> Scm <$ Regex.string "scm" <|> Sh <$ Regex.string "sh" + <|> Bash <$ Regex.string "bash" + <|> Toml <$ Regex.string "toml" -- | The cab dir is for temporary files and build outputs, not for source -- inputs. -- cgit v1.2.3