Skip to content

Could not deduce (MonadIO Maybe) arising from a use of ‘throwString’ on P110 #5

Description

@paulspencerwilliams

The provided findUserIdBySessionId function fails to compile

findUserIdBySessionId :: Redis r m => D.SessionId -> m (Maybe D.UserId)
findUserIdBySessionId sId = do
  result <- withConn $ R.get (encodeUtf8 sId)
  return $ case result of
    Right (Just uIdStr) -> readMay . unpack . decodeUtf8 $ uIdStr
    err                 -> throwString $ "Unexpected redis error: " <> show err

due to

    • Could not deduce (MonadIO Maybe)
        arising from a use of ‘throwString’
      from the context: Redis r m
        bound by the type signature for:
                   findUserIdBySessionId :: forall r (m :: * -> *).
                                            Redis r m =>
                                            D.SessionId -> m (Maybe D.UserId)
        at src/Adapter/Redis/Auth.hs:37:1-71
    • In the expression:
        throwString $ "Unexpected redis error: " <> show err
      In a case alternative:
          err -> throwString $ "Unexpected redis error: " <> show err
      In the second argument of ‘($)’, namely
        ‘case result of
           Right (Just uIdStr) -> readMay . unpack . decodeUtf8 $ uIdStr
           err -> throwString $ "Unexpected redis error: " <> show err’
   |
42 |     err                 -> throwString $ "Unexpected redis error: " <> show err

Pushing the return $ into the Right clause resolves this:

findUserIdBySessionId :: Redis r m => D.SessionId -> m (Maybe D.UserId)
findUserIdBySessionId sId = do
  result <- withConn $ R.get (encodeUtf8 sId)
  case result of
    Right (Just uIdStr) -> return $ readMay . unpack . decodeUtf8 $ uIdStr
    err                 -> throwString $ "Unexpected redis error: " <> show err

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions