11const _ = require ( 'lodash' )
2+ const la = require ( 'lazy-ass' )
3+ const is = require ( 'check-more-types' )
24const path = require ( 'path' )
35const debug = require ( 'debug' ) ( 'cypress:server:args' )
46const minimist = require ( 'minimist' )
57const coerceUtil = require ( './coerce' )
68const configUtil = require ( '../config' )
79const proxyUtil = require ( './proxy' )
10+ const errors = require ( '../errors' )
811
912const nestedObjectsInCurlyBracesRe = / \{ ( .+ ?) \} / g
1013const nestedArraysInSquareBracketsRe = / \[ ( .+ ?) \] / g
@@ -107,32 +110,41 @@ const JSONOrCoerce = (str) => {
107110 return coerceUtil ( str )
108111}
109112
110- const sanitizeAndConvertNestedArgs = ( str ) => {
113+ const sanitizeAndConvertNestedArgs = ( str , argname ) => {
114+ la ( is . unemptyString ( argname ) , 'missing config argname to be parsed' )
115+
116+ try {
111117 // if this is valid JSON then just
112118 // parse it and call it a day
113- const parsed = tryJSONParse ( str )
119+ const parsed = tryJSONParse ( str )
114120
115- if ( parsed ) {
116- return parsed
117- }
121+ if ( parsed ) {
122+ return parsed
123+ }
118124
119- // invalid JSON, so assume mixed usage
120- // first find foo={a:b,b:c} and bar=[1,2,3]
121- // syntax and turn those into
122- // foo: a:b|b:c
123- // bar: 1|2|3
124-
125- return _
126- . chain ( str )
127- . replace ( nestedObjectsInCurlyBracesRe , commasToPipes )
128- . replace ( nestedArraysInSquareBracketsRe , commasToPipes )
129- . split ( ',' )
130- . map ( ( pair ) => {
131- return pair . split ( everythingAfterFirstEqualRe )
132- } )
133- . fromPairs ( )
134- . mapValues ( JSONOrCoerce )
135- . value ( )
125+ // invalid JSON, so assume mixed usage
126+ // first find foo={a:b,b:c} and bar=[1,2,3]
127+ // syntax and turn those into
128+ // foo: a:b|b:c
129+ // bar: 1|2|3
130+
131+ return _
132+ . chain ( str )
133+ . replace ( nestedObjectsInCurlyBracesRe , commasToPipes )
134+ . replace ( nestedArraysInSquareBracketsRe , commasToPipes )
135+ . split ( ',' )
136+ . map ( ( pair ) => {
137+ return pair . split ( everythingAfterFirstEqualRe )
138+ } )
139+ . fromPairs ( )
140+ . mapValues ( JSONOrCoerce )
141+ . value ( )
142+ } catch ( err ) {
143+ debug ( 'could not pass config %s value %s' , argname , str )
144+ debug ( 'error %o' , err )
145+
146+ return errors . throw ( 'COULD_NOT_PARSE_ARGUMENTS' , argname , str , err . message )
147+ }
136148}
137149
138150module . exports = {
@@ -219,7 +231,7 @@ module.exports = {
219231 }
220232
221233 if ( env ) {
222- options . env = sanitizeAndConvertNestedArgs ( env )
234+ options . env = sanitizeAndConvertNestedArgs ( env , 'env' )
223235 }
224236
225237 const proxySource = proxyUtil . loadSystemProxySettings ( )
@@ -234,13 +246,13 @@ module.exports = {
234246 }
235247
236248 if ( reporterOptions ) {
237- options . reporterOptions = sanitizeAndConvertNestedArgs ( reporterOptions )
249+ options . reporterOptions = sanitizeAndConvertNestedArgs ( reporterOptions , 'reporterOptions' )
238250 }
239251
240252 if ( config ) {
241253 // convert config to an object
242- // annd store the config
243- options . config = sanitizeAndConvertNestedArgs ( config )
254+ // and store the config
255+ options . config = sanitizeAndConvertNestedArgs ( config , 'config' )
244256 }
245257
246258 // get a list of the available config keys
0 commit comments