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

Add file line numbers to errors #48

Merged
merged 2 commits into from
Jul 2, 2021
Merged

Conversation

saswatamcode
Copy link
Collaborator

This PR adds line numbers to errors in the following way,

CHANGELOG.md:275: "https://thanos.io/v0.15/components/query-frontend/" not accessible; status code 404: Not Found
CHANGELOG.md:829: link docs/proposals/201809_gossip-removal.md, normalized to: /Users/saswatamukherjee/web/thanos/docs/proposals/201809_gossip-removal.md: file not found
docs/storage.md:421,619,681,695,697,863 (6 occurrences): link design.md/#chunk, normalized to: /Users/saswatamukherjee/web/thanos/design.md: file not found

Fixes #36.

Signed-off-by: Saswata Mukherjee <[email protected]>
@saswatamcode saswatamcode requested a review from bwplotka June 19, 2021 13:45
@saswatamcode saswatamcode self-assigned this Jun 19, 2021
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! One suggestion

@@ -48,9 +48,9 @@ func NewChain(c ...mdformatter.LinkTransformer) mdformatter.LinkTransformer {
return &chain{chain: c}
}

func (l *chain) TransformDestination(ctx mdformatter.SourceContext, destination []byte) (_ []byte, err error) {
func (l *chain) TransformDestination(ctx mdformatter.SourceContext, destination []byte, lines string) (_ []byte, err error) {
Copy link
Owner

Choose a reason for hiding this comment

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

lines of what? do you mean lineNumber?

I find it very confusing we need to pass lines through transformers args 🤔

Why not adding it to SourceContext?

Copy link
Collaborator Author

@saswatamcode saswatamcode Jun 25, 2021

Choose a reason for hiding this comment

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

Didn't think of that. Will try to implement! 🙂

Signed-off-by: Saswata Mukherjee <[email protected]>
@saswatamcode saswatamcode requested a review from bwplotka June 25, 2021 03:15
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! Almost there ;p

@@ -75,6 +78,7 @@ func (t *transformer) Render(w io.Writer, source []byte, node ast.Node) error {
if token.Attr[i].Key != "src" {
continue
}
t.sourceCtx.LineNumbers = getLinkLines(source, []byte(token.Attr[i].Val), t.frontMatterLen)
Copy link
Owner

Choose a reason for hiding this comment

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

I am pretty sure we can get this directly from node (...) offset 🤔
Traversing huge file might get us quite latency problems... can we try that? 🤗

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! Will try to implement this! 🙂

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't seem to find any offset method/field which could give line numbers for a particular node. I could only find this method in text package but functionality seems to be different...

Copy link
Owner

Choose a reason for hiding this comment

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

It actually shows the offset in source 🤔 usually ;p

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.

Not fan of this reparsing source....

But should work for now. Let's optimize if needed later 👍🏽

@bwplotka bwplotka merged commit 2fac898 into bwplotka:main Jul 2, 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.

Add file line on error
2 participants