1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-02 20:37:08 +01:00

Improve JSON error handling.

Add support for detection of invalid line breaks in JSON string values.
Fixes #137. Could be improved to fetch the column number and drop the
messy grabbing of the line number from the exception message via regex,
but currently the "jsonlint" library (not to be confused with
"json-lint") only emits an error string. Since this is also the library
that drives http://jsonlint.com, we'll accept the messy regex in return
for more robust error checking when our default json-lint path fails.

All of the above only necessary because standard JSON.parse error
handling is broken in all environments. : )
This commit is contained in:
hacksalot
2016-02-12 17:11:11 -05:00
parent daeffd27b5
commit b26799f9fc
7 changed files with 69 additions and 27 deletions

12
dist/cli/error.js vendored
View File

@ -213,9 +213,15 @@ Error-handling routines for HackMyResume.
if (SyntaxErrorEx.is(ex.inner)) {
console.error(printf(M2C(this.msgs.readError.msg, 'red'), ex.file));
se = new SyntaxErrorEx(ex, ex.raw);
msg = printf(M2C(this.msgs.parseError.msg, 'red'), se.line, se.col);
} else if (ex.inner && ex.inner.line !== void 0 && ex.inner.col !== void 0) {
msg = printf(M2C(this.msgs.parseError.msg, 'red'), ex.inner.line, ex.inner.col);
if ((se.line != null) && (se.col != null)) {
msg = printf(M2C(this.msgs.parseError.msg[0], 'red'), se.line, se.col);
} else if (se.line != null) {
msg = printf(M2C(this.msgs.parseError.msg[1], 'red'), se.line);
} else {
msg = M2C(this.msgs.parseError.msg[2], 'red');
}
} else if (ex.inner && (ex.inner.line != null) && (ex.inner.col != null)) {
msg = printf(M2C(this.msgs.parseError.msg[0], 'red'), ex.inner.line, ex.inner.col);
} else {
msg = ex;
}

5
dist/cli/msg.yml vendored
View File

@ -81,7 +81,10 @@ errors:
readError:
msg: Reading **???** resume: **%s**
parseError:
msg: Invalid or corrupt JSON on line %s column %s.
msg:
- Invalid or corrupt JSON on line %s column %s.
- Invalid or corrupt JSON on line %s.
- Invalid or corrupt JSON.
invalidHelperUse:
msg: "**Warning**: Incorrect use of the **%s** theme helper."
fileSaveError: