From 8bb3bc50a24664d7a9425e83822c19592cd35056 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 22 May 2020 17:12:18 +0200 Subject: [PATCH] fix(correction-upload): better error messages wrt rating files --- messages/uniworx/de-de-formal.msg | 6 ++++-- messages/uniworx/en-eu.msg | 2 ++ src/Foundation/I18n.hs | 8 ++++++++ src/Handler/Utils/Rating.hs | 2 +- src/Handler/Utils/Submission.hs | 8 ++++---- src/Model/Rating.hs | 14 +++++++++++++- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/messages/uniworx/de-de-formal.msg b/messages/uniworx/de-de-formal.msg index 6b43fb150..de26df378 100644 --- a/messages/uniworx/de-de-formal.msg +++ b/messages/uniworx/de-de-formal.msg @@ -688,12 +688,14 @@ RatingNotExpected: Keine Bewertungen erlaubt RatingBinaryExpected: Bewertung muss 0 (=durchgefallen) oder 1 (=bestanden) sein RatingPointsRequired: Bewertung erfordert für dieses Blatt eine Punktzahl RatingFile: Bewertungsdatei +RatingFileException file@FilePath ratingException@Text: Beim Verarbeiten von Bewertungsdatei „#{file}“ ist folgender Fehler aufgetreten: #{ratingException} +RatingSubmissionException smid@CryptoFileNameSubmission ratingException@Text: Beim Verarbeiten der Bewertungsdatei für Abgabe „#{toPathPiece smid}“ ist folgender Fehler aufgetreten: #{ratingException} -SubmissionSinkExceptionDuplicateFileTitle file@FilePath: Dateiname #{show file} kommt mehrfach im Zip-Archiv vor +SubmissionSinkExceptionDuplicateFileTitle file@FilePath: Dateiname #{file} kommt mehrfach im Zip-Archiv vor SubmissionSinkExceptionDuplicateRating: Mehr als eine Bewertung gefunden. SubmissionSinkExceptionRatingWithoutUpdate: Bewertung gefunden, es ist hier aber keine Bewertung der Abgabe möglich. SubmissionSinkExceptionForeignRating smid@CryptoFileNameSubmission: Fremde Bewertung für Abgabe #{toPathPiece smid} enthalten. Bewertungen müssen sich immer auf die gleiche Abgabe beziehen! -SubmissionSinkExceptionInvalidFileTitleExtension file@FilePath: Dateiname „#{show file}“ hat keine der für dieses Übungsblatt zulässigen Dateiendungen. +SubmissionSinkExceptionInvalidFileTitleExtension file@FilePath: Dateiname „#{file}“ hat keine der für dieses Übungsblatt zulässigen Dateiendungen. MultiSinkException name@Text error@Text: In Abgabe „#{name}“ ist ein Fehler aufgetreten: #{error} diff --git a/messages/uniworx/en-eu.msg b/messages/uniworx/en-eu.msg index f96579fc6..171333ee9 100644 --- a/messages/uniworx/en-eu.msg +++ b/messages/uniworx/en-eu.msg @@ -685,6 +685,8 @@ RatingNotExpected: No marking points expected for this sheet RatingBinaryExpected: Marking must be 0 (=failed) or 1(=passed) RatingPointsRequired: Marking points required for this sheet RatingFile: Marking file +RatingFileException file ratingException: While processing the rating file “#{file}” the following error occurred: #{ratingException} +RatingSubmissionException smid ratingException: While processing the rating file for the submission “#{toPathPiece smid}” the following error occurred: #{ratingException} SubmissionSinkExceptionDuplicateFileTitle file: File #{show file} occurs multiple files within zip-archive. SubmissionSinkExceptionDuplicateRating: Found more than one marking file diff --git a/src/Foundation/I18n.hs b/src/Foundation/I18n.hs index fb353c46b..ea64b773e 100644 --- a/src/Foundation/I18n.hs +++ b/src/Foundation/I18n.hs @@ -205,6 +205,14 @@ embedRenderMessage ''UniWorX ''ExamGradingMode id embedRenderMessage ''UniWorX ''AuthenticationMode id +instance RenderMessage UniWorX RatingFileException where + renderMessage foundation ls = \case + RatingFileException{..} -> mr . MsgRatingFileException ratingExceptionFile $ mr ratingException + RatingSubmissionException{..} -> mr . MsgRatingSubmissionException ratingExceptionSubmission $ mr ratingException + where + mr :: RenderMessage UniWorX msg => msg -> Text + mr = renderMessage foundation ls + newtype ShortSex = ShortSex Sex embedRenderMessageVariant ''UniWorX ''ShortSex ("Short" <>) diff --git a/src/Handler/Utils/Rating.hs b/src/Handler/Utils/Rating.hs index d96ae3784..94bb2aaca 100644 --- a/src/Handler/Utils/Rating.hs +++ b/src/Handler/Utils/Rating.hs @@ -172,7 +172,7 @@ extractRatings = Conduit.mapM $ \f@File{..} -> do case () of _ | Just sId <- msId , isJust fileContent - -> Right . (sId, ) <$> parseRating f + -> handle (throwM . RatingFileException fileTitle) $ Right . (sId, ) <$> parseRating f | otherwise -> return $ Left f isRatingFile :: ( MonadHandler m diff --git a/src/Handler/Utils/Submission.hs b/src/Handler/Utils/Submission.hs index f45158877..62788038c 100644 --- a/src/Handler/Utils/Submission.hs +++ b/src/Handler/Utils/Submission.hs @@ -436,7 +436,7 @@ extractRatingsMsg = do -- | Nicht innerhalb von runDB aufrufen, damit das DB Rollback passieren kann! msgSubmissionErrors :: (MonadHandler m, MonadCatch m, HandlerSite m ~ UniWorX) => m a -> m (Maybe a) msgSubmissionErrors = flip catches - [ E.Handler $ \e -> Nothing <$ addMessageI Error (e :: RatingException) + [ E.Handler $ \e -> Nothing <$ addMessageI Error (e :: RatingFileException) , E.Handler $ \e -> Nothing <$ addMessageI Error (e :: SubmissionSinkException) , E.Handler $ \(SubmissionSinkException sinkId _ sinkEx) -> do mr <- getMessageRender @@ -552,9 +552,9 @@ sinkSubmission userId mExists isUpdate = do Right (submissionId', r) -> do $logDebugS "sinkSubmission" $ tshow submissionId' + cID <- encrypt submissionId' - unless (submissionId' == submissionId) $ do - cID <- encrypt submissionId' + unless (submissionId' == submissionId) $ throwM $ ForeignRating cID alreadySeen <- gets $ is (_Wrapped . _Just) . sinkSeenRating @@ -594,7 +594,7 @@ sinkSubmission userId mExists isUpdate = do Sheet{..} <- lift . getJust $ submissionSheet submission' - mapM_ throwM $ validateRating sheetType r' + mapM_ (throwM . RatingSubmissionException cID) $ validateRating sheetType r' when (submissionRatingDone submission' && not (submissionRatingDone submission)) $ tellSt mempty { sinkSubmissionNotifyRating = Any True } diff --git a/src/Model/Rating.hs b/src/Model/Rating.hs index 62f593d49..61e9591b2 100644 --- a/src/Model/Rating.hs +++ b/src/Model/Rating.hs @@ -2,6 +2,7 @@ module Model.Rating where import ClassyPrelude.Yesod import Model +import CryptoID -- import Data.Text (Text) import Data.Text.Encoding.Error (UnicodeException(..)) @@ -31,5 +32,16 @@ data RatingException = RatingNotUnicode UnicodeException -- ^ Rating failed to p | RatingBinaryExpected -- ^ Rating must be 0 or 1 | RatingPointsRequired -- ^ Rating without points for sheet that requires there to be points deriving (Show, Eq, Generic, Typeable) + deriving anyclass (Exception) -instance Exception RatingException +data RatingFileException + = RatingFileException + { ratingExceptionFile :: FilePath + , ratingException :: RatingException + } + | RatingSubmissionException + { ratingExceptionSubmission :: CryptoFileNameSubmission + , ratingException :: RatingException + } + deriving (Show, Eq, Generic, Typeable) + deriving anyclass (Exception)