1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-03 04:47:07 +01:00

Detect bad option files supplied via --options.

This commit is contained in:
hacksalot
2018-01-29 02:04:00 -05:00
parent 12a14dadeb
commit 17259cedbf
19 changed files with 149 additions and 13 deletions

View File

@ -226,6 +226,28 @@ assembleError = ( ex ) ->
msg = printf M2C( @msgs.validateError.msg ), ex.inner.toString()
etype = 'error'
when HMSTATUS.invalidOptionsFile
msg = M2C @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? and se.col?
msg += printf M2C( this.msgs.parseError.msg[0], 'red' ), se.line, se.col
else if se.line?
msg += printf M2C( this.msgs.parseError.msg[1], 'red' ), se.line
else
msg += M2C @msgs.parseError.msg[2], 'red'
else if ex.inner && ex.inner.line? && ex.inner.col?
msg += printf( M2C( this.msgs.parseError.msg[0], 'red' ), ex.inner.line, ex.inner.col)
else
msg += ex
msg += @msgs.invalidOptionsFile.msg[1]
etype = 'error'
when HMSTATUS.optionsFileNotFound
msg = M2C( @msgs.optionsFileNotFound.msg )
etype = 'error'
msg: msg # The error message to display
withStack: withStack # Whether to include the stack
quit: quit

View File

@ -40,6 +40,9 @@ process.argv (in production) or custom parameters (in test).
main = module.exports = ( rawArgs, exitCallback ) ->
initInfo = initialize( rawArgs, exitCallback )
if initInfo is null
return
args = initInfo.args
# Create the top-level (application) command...
@ -139,6 +142,16 @@ initialize = ( ar, exitCallback ) ->
_exitCallback = exitCallback || process.exit
o = initOptions ar
if o.ex
_err.init false, true, false
if( o.ex.op == 'parse' )
_err.err
fluenterror: if o.ex.op == 'parse' then HMSTATUS.invalidOptionsFile else 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 )
# Emit debug prelude if --debug was specified
@ -169,7 +182,6 @@ initialize = ( ar, exitCallback ) ->
, true
return
# Override the .helpInformation behavior
Command.prototype.helpInformation = ->
manPage = FS.readFileSync(
@ -210,6 +222,7 @@ initOptions = ( ar ) ->
if optStr && (optStr = optStr.trim())
#var myJSON = JSON.parse(optStr);
if( optStr[0] == '{')
# TODO: remove use of evil(). - hacksalot
### jshint ignore:start ###
oJSON = eval('(' + optStr + ')') # jshint ignore:line <-- no worky
### jshint ignore:end ###
@ -217,7 +230,8 @@ initOptions = ( ar ) ->
inf = safeLoadJSON( optStr )
if( !inf.ex )
oJSON = inf.json
# TODO: Error handling
else
return inf
# Grab the --debug flag, --silent, --assert and --no-color flags
isDebug = _.some args, (v) -> v == '-d' || v == '--debug'

View File

@ -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."

View File

@ -43,7 +43,7 @@ class FRESHTheme
if themeInfo.ex
throw
fluenterror:
if themeInfo.ex.operation == 'parse'
if themeInfo.ex.op == 'parse'
then HMSTATUS.parseError
else HMSTATUS.readError
inner: themeInfo.ex.inner

View File

@ -33,3 +33,5 @@ module.exports =
missingParam: 24
createError: 25
validateError: 26
invalidOptionsFile: 27
optionsFileNotFound: 28

View File

@ -17,7 +17,7 @@ module.exports = ( file ) ->
# We'll return HMSTATUS.readError or HMSTATUS.parseError.
retRaw = ret.raw && ret.raw.trim()
ret.ex =
operation: if retRaw then 'parse' else 'read'
op: if retRaw then 'parse' else 'read'
inner:
if SyntaxErrorEx.is( _error )
then (new SyntaxErrorEx( _error, retRaw ))

View File

@ -30,6 +30,7 @@ class SyntaxErrorEx
@line = (/on line (\d+)/.exec _error)[1]
# Return true if the supplied parameter is a JavaScript SyntaxError
SyntaxErrorEx.is = ( ex ) -> ex instanceof SyntaxError
module.exports = SyntaxErrorEx;

View File

@ -66,7 +66,7 @@ _peekOne = ( t, objPath ) ->
## safeLoadJSON can only return a READ error or a PARSE error
pkgError = null
if obj.ex
errCode = if obj.ex.operation == 'parse' then HMSTATUS.parseError else HMSTATUS.readError
errCode = if obj.ex.op == 'parse' then HMSTATUS.parseError else HMSTATUS.readError
if errCode == HMSTATUS.readError
obj.ex.quiet = true
pkgError = fluenterror: errCode, inner: obj.ex

View File

@ -83,7 +83,7 @@ _validateOne = (t, validator, schemas, opts) ->
# If failure, package JSON read/parse errors
else
if obj.ex.operation == 'parse'
if obj.ex.op == 'parse'
errCode = HMSTATUS.parseError
ret.status = 'broken'
else