From a6e4587281cb91a63d6901a1282c21739877283f Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Sun, 26 Jun 2022 13:54:37 +0000 Subject: [PATCH] Raise build-time error on incomplete patterns I realized I never intend to leave patterns (e.g. pattern matching in a 'case' clause) incomplete, i.e. some cases left missing. When I do that it means I forgot, and I'd like GHC to highlight it by raising an error instead of just warning. Vervis has lots of warnings so it's hard to detect among them. I suppose in other kinds of software people sometimes leave incomplete patterns intentionally / are okay with a runtime exception being thrown? In a web application, I definitely want to handle all cases, and be in control of how errors are handled and displayed in UI. --- src/Vervis/API.hs | 2 ++ src/Vervis/ActivityPub.hs | 1 + vervis.cabal | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Vervis/API.hs b/src/Vervis/API.hs index 6a8b47f..0c0dbcc 100644 --- a/src/Vervis/API.hs +++ b/src/Vervis/API.hs @@ -922,6 +922,8 @@ createNoteC (Entity pidUser personUser) sharerUser summary audience note muTarge if u == u' then Nothing else Just $ Right u' + checkParent _ _ = + error "A situation I missed in pattern matching, fix it?" checkFederation remoteRecips = do federation <- asksSite $ appFederation . appSettings unless (federation || null remoteRecips) $ diff --git a/src/Vervis/ActivityPub.hs b/src/Vervis/ActivityPub.hs index 569fcd2..73c69cb 100644 --- a/src/Vervis/ActivityPub.hs +++ b/src/Vervis/ActivityPub.hs @@ -1302,6 +1302,7 @@ getOutboxActorEntity obid = do (Just p, Nothing, Nothing) -> return $ ActorPerson p (Nothing, Just j, Nothing) -> return $ ActorProject j (Nothing, Nothing, Just r) -> return $ ActorRepo r + _ -> error "obid used by multiple actors" actorEntityPath (ActorPerson (Entity _ p)) = LocalActorSharer . sharerIdent <$> getJust (personIdent p) diff --git a/vervis.cabal b/vervis.cabal index 356c3ca..7657ab0 100644 --- a/vervis.cabal +++ b/vervis.cabal @@ -399,7 +399,7 @@ library if flag(dev) || flag(library-only) cpp-options: -DDEVELOPMENT - ghc-options: -Wall -fwarn-tabs -O0 + ghc-options: -Wall -fwarn-tabs -O0 -Werror=incomplete-patterns else ghc-options: -Wall -fwarn-tabs -O2