crystal-lang-tools / sublime-crystal

Crystal syntax highlighting for Sublime Text
Other
86 stars 18 forks source link

Formatting errors aren't properly handled when `auto_format` is enabled #32

Closed vladfaust closed 6 years ago

vladfaust commented 6 years ago

Given this file:

class Foo <

This is what I've got in the console:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 818, in run_
    return self.run(edit)
  File "crystal_format in /home/faust/.config/sublime-text-3/Installed Packages/sublime-crystal.sublime-package", line 52, in run
  File "./python3.3/json/__init__.py", line 316, in loads
  File "./python3.3/json/decoder.py", line 351, in decode
  File "./python3.3/json/decoder.py", line 369, in raw_decode
ValueError: No JSON object could be decoded
Traceback (most recent call last):
  File "./python3.3/json/decoder.py", line 367, in raw_decode
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 818, in run_
    return self.run(edit)

... and so on

Basic formatting works, but if there is an error in the code, it's not handled properly - no message is given except these errors in the console.

vladfaust commented 6 years ago

Any updates?

vladfaust commented 6 years ago

Bump, this is critical for me, anyone could reproduce it?

vladfaust commented 6 years ago

Really

faustinoaq commented 6 years ago

@vladfaust Sorry for the late response, I'm organizing the issues and PRs to track them easily :sweat_smile:

Check https://github.com/orgs/crystal-lang-tools/projects/1?fullscreen=true :wink:

vladfaust commented 6 years ago

@fgimian I would be happy if you could help me with that :cry:

fgimian commented 6 years ago

Yep, I can reproduce it as follows.

Ensure that auto_format is enabled (this is enabled by default in the Crystal Sublime extension). Then once saving the file:

Traceback (most recent call last):
  File "./python3.3/json/decoder.py", line 367, in raw_decode
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 1072, in run_
    return self.run(edit)
  File "/Users/fots/Library/Application Support/Sublime Text 3/Installed Packages/Crystal.sublime-package/crystal_format.py", line 52, in run
  File "./python3.3/json/__init__.py", line 316, in loads
  File "./python3.3/json/decoder.py", line 351, in decode
  File "./python3.3/json/decoder.py", line 369, in raw_decode
ValueError: No JSON object could be decoded

I'm sure we can fix this quite easily. I personally don't like auto_format to be enabled, especially by default, and thus I disable it myself so I've never noticed this problem.

If I get a little spare time, I'll try to assist with a fix for this extension.

Cheers Fotis

fgimian commented 6 years ago

The problem is simply that there's no exception handling in https://github.com/crystal-lang-tools/sublime-crystal/blob/master/crystal_format.py if things go wrong.

Cheers Fotis

fgimian commented 6 years ago

I'll be sending a pull request that fixes this in a sec guys 😄