Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Return sensible errors when semicolons are detected #2

Open
jarjee opened this issue Jan 28, 2020 · 0 comments
Open

Return sensible errors when semicolons are detected #2

jarjee opened this issue Jan 28, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@jarjee
Copy link
Collaborator

jarjee commented Jan 28, 2020

This is a pretty common mistake to make, and it's never valid to have a semicolon in ejson.

We can trap the case where a semicolon is found (in the wrong location), and then return a more sensible error message.

IE it could look something like this, if we can't get the numbers out more easily.

      const match = /Unexpected token \(([0-9]+):([0-9]+)\)/.exec(e.message);
      const line = Number(match[1]) - 1;
      const column = Number(match[2]) - 1;
      const char = input.split('\n')[line][column];

      if (char === ';') {
        throw new Error(`Unexpected semicolon at (${match[1]}:${match[2]})`);
      }
@jarjee jarjee added the enhancement New feature or request label Jan 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant