-
Notifications
You must be signed in to change notification settings - Fork 0
Fix panic line number and instruction parsing #103
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eee633b
Add tests that reproduces the panic line number issue.
Oleg-Melnik ba56d9d
Implement fixes for the panic line number issue.
Oleg-Melnik dbe5d1f
Fix golangci-lint issues in instruction parsing
Oleg-Melnik f2642a8
Merge branch 'master' into panic-line-number
Oleg-Melnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import ( | |
| "embed-code/embed-code-go/configuration" | ||
| "embed-code/embed-code-go/embedding" | ||
| "embed-code/embed-code-go/embedding/parsing" | ||
| "embed-code/embed-code-go/logging" | ||
| _type "embed-code/embed-code-go/type" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
|
|
@@ -142,6 +143,27 @@ var _ = Describe("Embedding", func() { | |
| Expect(errors.As(err, &parseErr)).Should(BeTrue()) | ||
| }) | ||
|
|
||
| // Regresses https://github.com/SpineEventEngine/embed-code-go/issues/19. | ||
| // | ||
| // The failure location must be a bare `file://...:line:column` URL so an | ||
| // IDE such as IntelliJ IDEA can open it from the console. Backticks around | ||
| // the URL and a missing column component prevent that navigation. | ||
|
Comment on lines
+148
to
+150
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| It("should format the failure location as a bare file URL with line and column", func() { | ||
| docPath := filepath.Join(GinkgoT().TempDir(), "doc.md") | ||
| processingErr := embedding.ProcessingError{ | ||
| DocFilePath: docPath, | ||
| Line: 2, | ||
| Err: errors.New("boom"), | ||
| } | ||
|
|
||
| message := processingErr.Error() | ||
|
|
||
| Expect(message).Should(ContainSubstring( | ||
| logging.FileReferenceWithPosition(docPath, 2, 1))) | ||
| Expect(message).Should(ContainSubstring(":2:1")) | ||
| Expect(message).ShouldNot(ContainSubstring("`")) | ||
| }) | ||
|
|
||
| It("should report all pattern matching errors", func() { | ||
| config.DocIncludes = []string{"missing-start-pattern.md", "missing-end-pattern.md"} | ||
|
|
||
|
|
@@ -243,7 +265,7 @@ var _ = Describe("Embedding", func() { | |
|
|
||
| Expect(err).Should(HaveOccurred()) | ||
| Expect(err.Error()).Should(ContainSubstring( | ||
| "missing-closing-tag.md:3`: " + | ||
| "missing-closing-tag.md:3:1: " + | ||
| "failed to parse an embedding instruction: " + | ||
| "the `<embed-code>` tag is not closed", | ||
| )) | ||
|
|
@@ -275,7 +297,7 @@ var _ = Describe("Embedding", func() { | |
|
|
||
| Expect(err).Should(HaveOccurred()) | ||
| Expect(err.Error()).Should(ContainSubstring( | ||
| "unclosed-nested-tag.md:3`: " + | ||
| "unclosed-nested-tag.md:3:1: " + | ||
| "failed to parse an embedding instruction: " + | ||
| "element <unexpected> closed by </embed-code>", | ||
| )) | ||
|
|
@@ -289,7 +311,7 @@ var _ = Describe("Embedding", func() { | |
|
|
||
| Expect(err).Should(HaveOccurred()) | ||
| Expect(err.Error()).Should(ContainSubstring( | ||
| "missing-code-fence.md:3`: " + | ||
| "missing-code-fence.md:3:1: " + | ||
| "expected a markdown code fence after the embedding instruction", | ||
| )) | ||
| }) | ||
|
|
@@ -302,7 +324,7 @@ var _ = Describe("Embedding", func() { | |
|
|
||
| Expect(err).Should(HaveOccurred()) | ||
| Expect(err.Error()).Should(ContainSubstring( | ||
| "unclosed-code-fence.md:3`: " + | ||
| "unclosed-code-fence.md:3:1: " + | ||
| "the markdown code fence after the embedding instruction is not closed", | ||
| )) | ||
| }) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,13 +44,22 @@ type ProcessingError struct { | |
| Err error | ||
| } | ||
|
|
||
| // errorLocationColumn is the column reported for a processing failure. The | ||
| // parser tracks line granularity only, so the location points at the beginning | ||
| // of the offending line. | ||
| const errorLocationColumn = 1 | ||
|
Comment on lines
+47
to
+50
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that we need to show column number, as it's always hardcoded to 1. I'm sure that link would be clickable even without column number. |
||
|
|
||
| // Error returns a user-facing description of the failed documentation processing operation. | ||
| // | ||
| // The documentation location is emitted as a bare `file://...:line:column` | ||
| // URL, without surrounding backticks, so IDEs such as IntelliJ IDEA can open | ||
| // it from the console. | ||
| // | ||
| // Returns formatted processing error text. | ||
| func (e ProcessingError) Error() string { | ||
| return fmt.Sprintf( | ||
| "failed to embed code fragment into doc file `%s`: %s", | ||
| logging.FileReferenceWithLine(e.DocFilePath, e.Line), | ||
| "failed to embed code fragment into doc file %s: %s", | ||
| logging.FileReferenceWithPosition(e.DocFilePath, e.Line, errorLocationColumn), | ||
| e.Err, | ||
| ) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not mention resolved (after we merge this PR) issues in the doc.
Same in all other places.