Skip to content
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

[#56] Dump all the errors from different files #141

Merged
merged 1 commit into from
Sep 23, 2022

Conversation

Sereja313
Copy link
Member

@Sereja313 Sereja313 commented Sep 13, 2022

Description

Problem: Currently, xrefcheck fails immediately after the first observed error because die is used right in markdownScanner What we want is dumping all the errors from different markdowns and then print them as a final xrefcheck's result together with the broken links. Also, despite the fact that in the makeError function we have 4 error messages, 2 of them are not reported, and the test case that should check this only checks that at least one of the four files throws an error.

it "Check if parsing incorrect markdowns produce exceptions" $ do
areIncorrect <- mapM (isIncorrectMD GitHub) failPaths
or areIncorrect `shouldBe` True

Solution: Make xrefcheck to report all errors. Add ScanError type and propagate errors to report all of them, rather than failing immediately after the first error is detected.

Related issue(s)

Fixes #56

✅ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this
checkmark indicating that you are sure it is dealt with (be that by irrelevance).

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
  • Public contracts

    • Any modifications of public contracts comply with the Evolution
      of Public Contracts
      policy.
    • I added an entry to the changelog if my changes are visible to the users
      and
    • provided a migration guide for breaking changes if possible

Stylistic guide (mandatory)

tests/golden/check-scan-errors/expected.gold Show resolved Hide resolved
src/Xrefcheck/Command.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
tests/golden/check-scan-errors/expected.gold Show resolved Hide resolved
@dcastro
Copy link
Member

dcastro commented Sep 17, 2022

Also, despite the fact that in the makeError function we have 4 error messages, 2 of them are not reported, and the test case that should check this only checks that at least one of the four files throws an error.

Great catch! 👏 Thank you for fixing this and adding these tests, it really helped uncover lots of issues with the existing code, well done!

src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
Comment on lines 37 to 44
it "Check if ignore link annotation produce error when placed at the end of file" do
let file = "tests/markdowns/with-annotations/no_link_eof.md"
getErrs file `shouldReturn`
makeError (Just $ PosInfo 9 1 9 31) file Link ""
it "Check if ignore paragraph annotation produce error when placed at the end of file" do
let file = "tests/markdowns/with-annotations/no_paragraph_eof.md"
getErrs file `shouldReturn`
makeError (Just $ PosInfo 9 1 9 36) file Paragraph "EOF"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be even better if these 2 new tests were written in bats instead, because then we can see whether the error message printed to stdout is sensible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this manually, it seems there's a double space in "but found^^EOF".

Copy link
Member

@dcastro dcastro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from that single comment above, LGTM, so I'm pre-approving 😄

Please merge after handling that comment, and I'll cut the 0.2.1 release 🎉

@Sereja313 Sereja313 force-pushed the Sereja313/#56-dump-all-errors-from-files branch from 185a752 to bf5501e Compare September 22, 2022 20:01
@Sereja313
Copy link
Member Author

@dcastro looks like readDirectoryWithL scans files in a different order on different machines(test in bf5501e works for me but doesn't work in CI and vice versa for 069434e).
Do I need to sort scan errors (or perhaps file paths in a directory tree before scanning) to make tests reproducible?

@dcastro
Copy link
Member

dcastro commented Sep 23, 2022

@Sereja313 Sounds like a good idea!

sort scan errors (or perhaps file paths in a directory tree before scanning)

Whichever way you prefer

Problem: Currently, xrefcheck fails immediately after the first
observed error because `die` is used right in `markdownScanner` What
we want is dumping all the errors from different markdowns and then
print them as a final xrefcheck's result together with the broken
links. Also, despite the fact that in the `makeError` function we have
4 error messages, 2 of them are not reported, and the test case that
should check this only checks that at least one of the four files
throws an error.

Solution: Make xrefcheck to report all errors. Add `ScanError` type
and propagate errors to report all of them, rather than failing
immediately after the first error is detected.
@Sereja313 Sereja313 force-pushed the Sereja313/#56-dump-all-errors-from-files branch from ea21a9e to c8d19a3 Compare September 23, 2022 07:15
@Sereja313 Sereja313 merged commit d3b1cb5 into master Sep 23, 2022
@Sereja313 Sereja313 deleted the Sereja313/#56-dump-all-errors-from-files branch September 23, 2022 07:17
@Sereja313
Copy link
Member Author

Done 🎉

@dcastro
Copy link
Member

dcastro commented Sep 23, 2022

Great work @Sereja313! 😄 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dump all the errors from different files
3 participants