Skip to content

Add file line numbers to errors#48

Merged
bwplotka merged 2 commits intobwplotka:mainfrom
saswatamcode:line-number
Jul 2, 2021
Merged

Add file line numbers to errors#48
bwplotka merged 2 commits intobwplotka:mainfrom
saswatamcode:line-number

Conversation

@saswatamcode
Copy link
Copy Markdown
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 <saswataminsta@yahoo.com>
@saswatamcode saswatamcode requested a review from bwplotka June 19, 2021 13:45
@saswatamcode saswatamcode self-assigned this Jun 19, 2021
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! One suggestion

}

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
Copy Markdown
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
Copy Markdown
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 <saswataminsta@yahoo.com>
@saswatamcode saswatamcode requested a review from bwplotka June 25, 2021 03:15
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! Almost there ;p

if token.Attr[i].Key != "src" {
continue
}
t.sourceCtx.LineNumbers = getLinkLines(source, []byte(token.Attr[i].Val), t.frontMatterLen)
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.

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
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.

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