mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-02 20:37:08 +01:00
Detect bad option files supplied via --options.
This commit is contained in:
24
dist/cli/error.js
vendored
24
dist/cli/error.js
vendored
@ -234,6 +234,30 @@ Error-handling routines for HackMyResume.
|
||||
case HMSTATUS.validateError:
|
||||
msg = printf(M2C(this.msgs.validateError.msg), ex.inner.toString());
|
||||
etype = 'error';
|
||||
break;
|
||||
case HMSTATUS.invalidOptionsFile:
|
||||
msg = M2C(this.msgs.invalidOptionsFile.msg[0]);
|
||||
if (SyntaxErrorEx.is(ex.inner)) {
|
||||
console.error(printf(M2C(this.msgs.readError.msg, 'red'), ex.file));
|
||||
se = new SyntaxErrorEx(ex, ex.raw);
|
||||
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;
|
||||
}
|
||||
msg += this.msgs.invalidOptionsFile.msg[1];
|
||||
etype = 'error';
|
||||
break;
|
||||
case HMSTATUS.optionsFileNotFound:
|
||||
msg = M2C(this.msgs.optionsFileNotFound.msg);
|
||||
etype = 'error';
|
||||
}
|
||||
return {
|
||||
msg: msg,
|
||||
|
22
dist/cli/main.js
vendored
22
dist/cli/main.js
vendored
@ -62,6 +62,9 @@ Definition of the `main` function.
|
||||
main = module.exports = function(rawArgs, exitCallback) {
|
||||
var args, initInfo, program;
|
||||
initInfo = initialize(rawArgs, exitCallback);
|
||||
if (initInfo === null) {
|
||||
return;
|
||||
}
|
||||
args = initInfo.args;
|
||||
program = new Command('hackmyresume').version(PKG.version).description(chalk.yellow.bold('*** HackMyResume ***')).option('-s --silent', 'Run in silent mode').option('--no-color', 'Disable colors').option('--color', 'Enable colors').option('-d --debug', 'Enable diagnostics', false).option('-a --assert', 'Treat warnings as errors', false).option('-v --version', 'Show the version').allowUnknownOption();
|
||||
program.jsonArgs = initInfo.options;
|
||||
@ -104,6 +107,23 @@ Definition of the `main` function.
|
||||
var o;
|
||||
_exitCallback = exitCallback || process.exit;
|
||||
o = initOptions(ar);
|
||||
if (o.ex) {
|
||||
_err.init(false, true, false);
|
||||
if (o.ex.op === 'parse') {
|
||||
_err.err({
|
||||
fluenterror: o.ex.op === 'parse' ? HMSTATUS.invalidOptionsFile : HMSTATUS.optionsFileNotFound,
|
||||
inner: o.ex.inner,
|
||||
quit: true
|
||||
});
|
||||
} else {
|
||||
_err.err({
|
||||
fluenterror: HMSTATUS.optionsFileNotFound,
|
||||
inner: o.ex.inner,
|
||||
quit: true
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
o.silent || logMsg(_title);
|
||||
if (o.debug) {
|
||||
_out.log(chalk.cyan('The -d or --debug switch was specified. DEBUG mode engaged.'));
|
||||
@ -173,6 +193,8 @@ Definition of the `main` function.
|
||||
inf = safeLoadJSON(optStr);
|
||||
if (!inf.ex) {
|
||||
oJSON = inf.json;
|
||||
} else {
|
||||
return inf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
dist/cli/msg.yml
vendored
6
dist/cli/msg.yml
vendored
@ -109,3 +109,9 @@ errors:
|
||||
msg: Exiting with status code **%s**.
|
||||
validateError:
|
||||
msg: "An error occurred during validation:\n%s"
|
||||
invalidOptionsFile:
|
||||
msg:
|
||||
- "The specified options file is invalid:\n"
|
||||
- "\nMake sure the options file contains valid JSON."
|
||||
optionsFileNotFound:
|
||||
msg: "The specified options file is missing or inaccessible."
|
||||
|
2
dist/core/fresh-theme.js
vendored
2
dist/core/fresh-theme.js
vendored
@ -50,7 +50,7 @@ Definition of the FRESHTheme class.
|
||||
themeInfo = loadSafeJson(themeFile);
|
||||
if (themeInfo.ex) {
|
||||
throw {
|
||||
fluenterror: themeInfo.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError,
|
||||
fluenterror: themeInfo.ex.op === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError,
|
||||
inner: themeInfo.ex.inner
|
||||
};
|
||||
}
|
||||
|
4
dist/core/status-codes.js
vendored
4
dist/core/status-codes.js
vendored
@ -33,7 +33,9 @@ Status codes for HackMyResume.
|
||||
invalidParamCount: 23,
|
||||
missingParam: 24,
|
||||
createError: 25,
|
||||
validateError: 26
|
||||
validateError: 26,
|
||||
invalidOptionsFile: 27,
|
||||
optionsFileNotFound: 28
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
|
2
dist/utils/safe-json-loader.js
vendored
2
dist/utils/safe-json-loader.js
vendored
@ -21,7 +21,7 @@ Definition of the SafeJsonLoader class.
|
||||
} catch (_error) {
|
||||
retRaw = ret.raw && ret.raw.trim();
|
||||
ret.ex = {
|
||||
operation: retRaw ? 'parse' : 'read',
|
||||
op: retRaw ? 'parse' : 'read',
|
||||
inner: SyntaxErrorEx.is(_error) ? new SyntaxErrorEx(_error, retRaw) : _error,
|
||||
file: file
|
||||
};
|
||||
|
2
dist/verbs/peek.js
vendored
2
dist/verbs/peek.js
vendored
@ -80,7 +80,7 @@ Implementation of the 'peek' verb for HackMyResume.
|
||||
}
|
||||
pkgError = null;
|
||||
if (obj.ex) {
|
||||
errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
errCode = obj.ex.op === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
if (errCode === HMSTATUS.readError) {
|
||||
obj.ex.quiet = true;
|
||||
}
|
||||
|
2
dist/verbs/validate.js
vendored
2
dist/verbs/validate.js
vendored
@ -111,7 +111,7 @@ Implementation of the 'validate' verb for HackMyResume.
|
||||
ret.violations = validate.errors;
|
||||
}
|
||||
} else {
|
||||
if (obj.ex.operation === 'parse') {
|
||||
if (obj.ex.op === 'parse') {
|
||||
errCode = HMSTATUS.parseError;
|
||||
ret.status = 'broken';
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user