atom / first-mate

TextMate helpers
http://atom.github.io/first-mate
MIT License
91 stars 57 forks source link

Need file name and line number on syntax errors #51

Open mrjbq7 opened 9 years ago

mrjbq7 commented 9 years ago

I was trying to convert Factor's textmate bundle to work with Atom and had an error while running apm:

$ apm init --package atom --convert Factor.tmbundle

/opt/homebrew-cask/Caskroom/atom/latest/Atom.app/Contents/Resources/app/apm/node_modules/first-mate/lib/scope-selector-parser.js:954
      throw peg$buildException(null, peg$maxFailExpected, peg$maxFailPos);
            ^
SyntaxError: Expected ",", ".", [ \t], [*], [a-zA-Z0-9+_], [a-zA-Z0-9\-+_], [|&\-] or end of input but "\n" found.

This error didn't say which file, nor which position in the file was having the syntax error, which made debugging really difficult. By process of elimination, I was able to remove files until I found the offending file, which was this version:

https://github.com/slavapestov/factor/blob/70428241bd2f6f96e31b121690f337c466bed942/misc/Factor.tmbundle/Snippets/%5B%20expanded.tmSnippet

The fix was to remove the extra newline after source.factor (https://github.com/slavapestov/factor/commit/2b1e7dd9d06f004e9b2f5a86b5d406cafd4185ef).

Anyway, it would be super awesome if you could add file/line/column to the error messages.

Thanks!

izuzak commented 9 years ago

Thanks for the feedback, @mrjbq7.

@nathansobo you were looking at first-mate recently -- would we consider tweaking first-mate so that it extracts the line and column number from the pegjs exception and adds it to the exception message (probably here)? Or should we just tweak apm to do that when it calls first-mate?

nathansobo commented 9 years ago

It makes sense to modify first mate to get that information. I'm somewhat surprised it's not already in the error message. We should just catch the exception and build/rethrow a new one with a better message.

FrederickGeek8 commented 7 years ago

I know this is an old issue but it is still open and unresolved, so I thought I'd try my hand at trying to fix it. I decided to apply the fix in APM since the information required to locate the source of the error is not made available to first-mate.

Additionally, it appears to be near impossible (or at least efficient) to ascertain an exact location of an error, so I elected to output the malformed piece of text instead, which should hopefully give enough information to the user to debug their program.

Ingramz commented 7 years ago

Seems to be duplicate of #23

mrjbq7 commented 7 years ago

I was not complaining about receiving the syntax error (that was just an example). Instead I was suggesting debugging it was hard without file name and line numbers available. I don't think this issue is duplicate of #23.

Ingramz commented 7 years ago

From first-mate's perspective it is the same as #23, if not duplicate, then certainly related. Conversion takes place in apm (and first-mate never sees the complete file being converted, thus being oblivious of any sort of positional information), which @FrederickGeek8 has taken care of in his pull request.