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

TypeError: Cannot create property 'rules' on string 'SyntaxError' #18

Closed
asbjornu opened this issue Jun 12, 2020 · 3 comments · Fixed by #21
Closed

TypeError: Cannot create property 'rules' on string 'SyntaxError' #18

asbjornu opened this issue Jun 12, 2020 · 3 comments · Fixed by #21

Comments

@asbjornu
Copy link
Collaborator

This Liquid-Markdown file causes vscode-remark to crash with the following error message when I try to format the file in VS Code:

TypeError: Cannot create property 'rules' on string 'SyntaxError'

It would be good to know where the syntax error occurs so it could be fixed in the document. Even better would be for vscode-remark to handle formatting of the Markdown document without any problems.

@asbjornu
Copy link
Collaborator Author

Even just selecting the following list in the same Markdown document and doing "Format Selection" leads to the same error:

* When initiating a `Purchase` payment order, you need to make sure that the
  field `generateRecurrenceToken` is set to `true`. This recurrence token
  will stored in the [authorization transaction][transaction]
  sub-resource on the underlying payment resource.
* When initiating a `Verify` payment order, a recurrence token will be generated
  automatically. This recurrence token is stored in the
  [verification][verification-transaction]  sub-resource on the underlying
  payment resource.

@asbjornu
Copy link
Collaborator Author

I may have figured out what's going on here. Creating a .remarkrc.yml file seems to consistently produce this error. Might it be the case that vscode-remark tries to parse .remarkrc.yml as JSON?

@asbjornu
Copy link
Collaborator Author

asbjornu commented Jun 26, 2020

Yep, seems like '**/*remarkrc*' is always parsed as JSON:

https://github.com/mrmlnc/vscode-remark/blob/fad8495e238ad2d3f312733ca09049761862f960/src/extension.ts#L61-L67

Since SyntaxError is returned here instead of actually throwing an error, SyntaxError is treated as valid config by whichever method is calling getWorkspaceConfig which is pretty poor form.

I see a lot of catch (err) { return 'SyntaxError'; } around in the codebase, which is not only swallowing the error and making it impossible to figure out what the actual probelm is, but it makes the vscode-remark codebase think that everything is okay and merrily continue attempting to use 'SyntaxProblem' as a valid object of the type that was supposed to be returned.

Sorry, but this is pretty bad. While parsing .remarkrc.yml as YAML would fix my issue, I think the whole codebase needs a revision to stop swallowing errors and returning strings as though they were valid objects. Why are those catch statements there in the first place? Can't the errors just bubble up to VS Code so they can be displayed in the console?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant