Skip to content

Commit bf05aec

Browse files
committed
Hide erros about non-exhaustive pattern matches
There is a problem in sendCommand message that we process some commands first and compiler can't infer that they are not reachable in the next clauses. It's possible to ignore the message, but it will require developer to observe the code each time in order to check if we have not introduced a new error. Another possibility is to introduce a datatype for all the commands and try make GHC infter the unreachability of the clause — probably it's the best scenario but it's a major change to the library, that can affect downstream packages. So now we added a error message that works as a comment to the code and will provide a reasonable error to the user if ever triggered
1 parent f19c889 commit bf05aec

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/Network/HaskellNet/POP3.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ sendCommand conn command =
159159
(UIDL msg) -> "UIDL " ++ maybe "" show msg
160160
(APOP usern passw) -> "APOP " ++ usern ++ " " ++
161161
hexDigest (apopKey conn ++ passw)
162+
AUTH _ _ _ -> error "sendCommand: impossible happened AUTH expected to be processed in the preceeding clause"
163+
RETR _ -> error "sendCommand: impossible happened AUTH expected to be processed in the preceeding clause"
164+
TOP _ _ -> error "sendCommand: impossible happened AUTH expected to be processed in the preceeding clause"
162165

163166
user :: POP3Connection -> String -> IO ()
164167
user conn name = do (resp, _) <- sendCommand conn (USER name)

src/Network/HaskellNet/SMTP/Internal.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ sendCommand (SMTPC conn _) meth =
302302
NOOP -> "NOOP"
303303
RSET -> "RSET"
304304
QUIT -> "QUIT"
305+
DATA _ -> error "sendCommand: impossible happened DATA command expected to be processed in thepreceeding clause"
306+
AUTH _ _ _ -> error "sendCommand: impossible happened AUTH command expected to be processed in the preceeding clause"
305307

306308
-- | Sends quit to the server. Connection must be terminated afterwards, i.e. it's not
307309
-- allowed to issue any command on this connection.

0 commit comments

Comments
 (0)