-
Notifications
You must be signed in to change notification settings - Fork 3
[TSD-70] Exception handling when reading log files #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| -- | Given number of file of inspect, knowledgebase and attachment, | ||
| -- analyze the logs and return the results. | ||
| inspectAttachment :: Config -> TicketInfo -> AttachmentContent -> ZendeskResponse | ||
| inspectAttachment :: (MonadCatch m) => Config -> TicketInfo -> AttachmentContent -> m ZendeskResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't touch this, this is all pure, no need to infect that part of the code with impurities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!
src/Lib.hs
Outdated
| att <- MaybeT $ getAttachment lastAttachment | ||
|
|
||
| pure $ inspectAttachment config ticketInfo att | ||
| catchAny (inspectAttachment config ticketInfo att) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not looking for Any exception, we need specific exceptions we can throw and catch. Like here - https://github.com/input-output-hk/cardano-sl/blob/feature/CBR-163/wallet-new/src/Cardano/Wallet/WalletLayer/Error.hs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the advice! Will look into it!
|
Implemented obvious ones. Now I'm going to try to solve exception |
7b41e15 to
54d39b7
Compare
src/Lib.hs
Outdated
| -- analyze the logs and return the results. | ||
| inspectAttachment :: Config -> TicketInfo -> AttachmentContent -> ZendeskResponse | ||
| inspectAttachment Config{..} ticketInfo@TicketInfo{..} attContent = do | ||
| inspectAttachment :: Config -> TicketInfo -> [LByteString]-> ZendeskResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you strip the newtype wrapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, previously, we were passing raw zip file asAttachmentContent whereas I've changed it to pass the decompressed log files.
The only way I found of making this function pure is to decompress the file before passing it instead of decompressing it inside of this function.
| , MonadReader Config | ||
| , MonadIO | ||
| , MonadBase IO | ||
| , MonadCatch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really think we don't need this, unless you want to re-export, but that's a whole different story.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I thought that was from the module exports 😁
Should have looked in more detail.
log-classifier.cabal
Outdated
| , optparse-applicative | ||
| , reflection | ||
| , regex-tdfa | ||
| , safe-exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure we need this? http://hackage.haskell.org/package/universum-1.2.0/docs/Universum-Exception.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried importing tryDeep from Universum.Exceptions but didn't work. I'm not sure what they mean by re-export. Perhaps it's because we're using the older version of universum (1.1.0)
cardano-sl 's wallet-new component is importing safe-exceptions even though it's using universum as well.
https://github.com/input-output-hk/cardano-sl/blob/develop/wallet-new/cardano-sl-wallet-new.cabal#L175
Maybe there's some way to import it and I just don't know how.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, keep it there, just try using functions from Universum as much as possible.
src/Lib.hs
Outdated
| postTicketComment <- asksZendeskLayer zlPostTicketComment | ||
|
|
||
|
|
||
| -- What should we do if the zendeskResponse was Nothing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point of this refactoring is to add error details and remove Maybe where possible. Maybe you would have an idea what to do with it if you had specific exceptions you could catch here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay, I'd tackle on that part once I'm done with handling the decompression issue..
| -- Why tryDeep instead of try? It's because we need to fully evaluate bytestrings in order to catch | ||
| -- the decompression issue. | ||
| readZip :: (MonadCatch m, MonadIO m) => LByteString -> m (Map FilePath LByteString) | ||
| readZip rawzip = case Zip.toArchiveOrFail rawzip of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you try it out? Does it catch the exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I did try to use try at first since it has less constraints but it didn't catch the decompression error.
I can try again.
63d68e1 to
8a6cb8f
Compare
src/DataSource/Types.hs
Outdated
| coComment :: Comment | ||
| } | ||
|
|
||
| newtype LogFiles = LogFiles { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the formatting seen here - https://github.com/input-output-hk/log-classifier/pull/26/files#diff-ee661ebeb72d3f09577f0fd782917c5aR359 since it doesn't change any other lines besides the ones you change which is helpful.
| -- Check we have some comments. | ||
| assert $ isLeft (eZendeskResponse :: Either ProcessTicketExceptions ZendeskResponse) | ||
| whenLeft eZendeskResponse $ \processException -> | ||
| assert $ processException == TicketInfoNotFound ticketId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
src/Lib.hs
Outdated
| att <- MaybeT $ getAttachment lastAttachment | ||
|
|
||
| pure $ inspectAttachment config ticketInfo att | ||
| mAtt <- runMaybeT $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems overly verbose. Can you move it around a bit to make it a bit more concise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try it out. Thank you.
| -- Check it throws exception | ||
| -- How do I check if it returns proper exception? | ||
| assert $ isLeft (eZendeskResponse :: Either ProcessTicketExceptions ZendeskResponse) | ||
| whenLeft eZendeskResponse $ \processException -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work.
3e0add1 to
f219ec7
Compare
e0f0ae4 to
f179118
Compare
ksaric
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
src/Lib.hs
Outdated
| att <- MaybeT $ getAttachment lastAttachment | ||
|
|
||
| pure $ inspectAttachment config ticketInfo att | ||
| lastAttach <- handleMaybe (safeHead . reverse . sort $ attachments) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleMaybe . safeHead . reverse . sort $ attachments
test/Spec.hs
Outdated
|
|
||
| -- Check we have some comments. | ||
| assert $ isJust zendeskResponse | ||
| assert $ (not . null . zrComment) zendeskResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert . not . null . zrComment $ zendeskResponse
mdimjasevic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far I finishing reading everything but the tests, which looks good. I'll finish with tests tomorrow.
src/Lib.hs
Outdated
| -- No attachment, no comments means something is wrong with ticket itself | ||
|
|
||
| -- | Inspect only the latest attachment. We could propagate this | ||
| -- @Maybe@ upwards or use an @Either@ which will go hand in hand |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the documentation of the inspectAttachments function be updated now that the return type is not App (Maybe ZendeskResponse) anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'll update it.
27c6092 to
5a7719a
Compare
mdimjasevic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I with the test/Spec.hs was better organised: it looks like there is a lot of repetition of very similar code.
Other than that, this looks good to me.
This PR will introduce exception handling on reading log files so that the program will not crash due to the corrupted log file.
https://iohk.myjetbrains.com/youtrack/issue/TSD-70