Skip to content

Fix clilog file names for link errors#31

Merged
bwplotka merged 2 commits intobwplotka:mainfrom
saswatamcode:clilog-fix
May 19, 2021
Merged

Fix clilog file names for link errors#31
bwplotka merged 2 commits intobwplotka:mainfrom
saswatamcode:clilog-fix

Conversation

@saswatamcode
Copy link
Copy Markdown
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 <saswataminsta@yahoo.com>
Copy link
Copy Markdown
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


merr := merrors.New()
base, err := os.Getwd()
if err != nil {
Copy link
Copy Markdown
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
Copy Markdown
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 <saswataminsta@yahoo.com>
Copy link
Copy Markdown
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