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

Fix clilog file names for link errors #31

Merged
merged 2 commits into from
May 19, 2021

Conversation

saswatamcode
Copy link
Collaborator

Fixes #28.
Currently, link checking errors are handled by merrors and are pretty printed when log.format is set to clilog(this is set to default since it is human-readable). However the filenames of the relevant errors are not shown in clilog even though it is wrapped. This is due to the PrettyPrint function which in turn calls errors.As(). According to docs the passed in error is repeatedly unwrapped which causes us to lose the filename. There is also no way to pass in the filename without losing the pretty print functionality,

This PR fixes this by wrapping each error with the relative path of the file it originates from thus allowing us to have logs like below,

error: 31 errors:
5 errors:
                getting-started.md: link /scripts/quickstart.sh, normalized to: /Users/saswatamukherjee/web/thanos/docs/scripts/quickstart.sh: file not found
                getting-started.md: link /examples/dashboards/dashboards.md, normalized to: /Users/saswatamukherjee/web/thanos/docs/examples/dashboards/dashboards.md: file not found
                getting-started.md: link /examples/alerts/alerts.md, normalized to: /Users/saswatamukherjee/web/thanos/docs/examples/alerts/alerts.md: file not found
                getting-started.md: link /MAINTAINERS.md, normalized to: /Users/saswatamukherjee/web/thanos/docs/MAINTAINERS.md: file not found
                getting-started.md: link /CONTRIBUTING.md, normalized to: /Users/saswatamukherjee/web/thanos/docs/CONTRIBUTING.md: file not found

Signed-off-by: Saswata Mukherjee <[email protected]>
Copy link
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Nice! Some implementation nits only

@@ -201,14 +201,23 @@ func (v *validator) Close(ctx mdformatter.SourceContext) error {
})

merr := merrors.New()
base, err := os.Getwd()
if err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

Couple of things:

  • merr.Add already checks if err != nil so no need to check again
  • Don't wrap with Wrapf if there is no argument, use just Wrap
  • No need to say something failed - you are wrapping failure after all, so just resolve working dir would be ok
  • Are we sure we want to continue after those errors and not fail whole thing? why?

Copy link
Collaborator Author

@saswatamcode saswatamcode May 19, 2021

Choose a reason for hiding this comment

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

Oh yes! Would be better to fail whole thing and return error rather than add to merr. Will implement this! Would need to keep err != nil checks in this case.

Signed-off-by: Saswata Mukherjee <[email protected]>
Copy link
Owner

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks 💪🏽 Solid

@bwplotka bwplotka merged commit 26387e8 into bwplotka:main May 19, 2021
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.

File name/path for link errors doesn't show
2 participants