HaxeCheckstyle / haxe-formatter

Haxe code formatter based on tokentree
https://haxecheckstyle.github.io/haxe-formatter-docs/#codesamples.CommonSamples.allman_curlies
MIT License
72 stars 16 forks source link

Unclear error message when hxformat.json is invalid JSON #300

Open gene-pavlovsky opened 5 years ago

gene-pavlovsky commented 5 years ago

Describe the bug
If there are syntax error in hxformat.json, such as the extraneous comma in the example below, the error message doesn't explain the actual problem with the config.

hxformat.json

{
    "wrapping": {
        "opBoolChain": {
            "defaultWrap": "keep",
        }
    }
}

Expected output (e.g. from jsonlint)

# "jsonlint.cmd" hxformat.json
Error: Parse error on line 4:
}       }       }",
----------------------^
Expecting 'STRING', got '}'
...

Actual output (repeated once for every input file! more reasonable to print it once and abort)

src/formatter/config/Config.hx:48: TypeError: Cannot read property 'emptyLines' of undefined

Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 10085 column 51
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 10059 column 8
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8798 column 10
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8744 column 22
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8643 column 43
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8630 column 10
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8628 column 10
Called from C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8564 column 7
Called from formatter_Cli.main (C:\Users\USER\AppData\Roaming\haxe\haxe_libraries\formatter\1.3.0\haxelib\run.js line 8570 column 2)
AlexHaxe commented 5 years ago

The current solution reports one line for every file (I removed stacktraces). Formatter doesn't track or cache hxformat.json files and will run a new detection and load for every single file.

I guess technically the error message hasn't changed much with my fix, so feel free to reopen...