File tree Expand file tree Collapse file tree 1 file changed +18
-10
lines changed
Expand file tree Collapse file tree 1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -173,21 +173,29 @@ export class Operators implements WithTaskOptions<Operators> {
173173
174174 arrays = this . values ( arrays ) as [ any , any ]
175175
176- if ( arrays . length !== 2 ) {
177- throw {
178- operator : "Merge by keys" ,
179- msg : "Expected an array of 2 elements." ,
180- value : arrays
176+ const validateOrThrow = ( operator : string , items : any [ ] ) => {
177+ const firstInvalid = items . find ( item => ! item . isValid )
178+
179+ if ( firstInvalid ) {
180+ throw {
181+ operator,
182+ ...firstInvalid
183+ }
181184 }
182185 }
183186
184- if ( ! keys ) {
185- throw {
186- operator : "Merge by keys" ,
187+ validateOrThrow ( "Merge by keys" , [
188+ {
189+ isValid : arrays . length === 2 ,
190+ msg : "Expected an array of 2 elements." ,
191+ value : arrays
192+ } ,
193+ {
194+ isValid : keys ,
187195 msg : "Expected a 'true' value for keys." ,
188- value : keys
196+ value : keys ,
189197 }
190- }
198+ ] )
191199
192200 const [ array1 , array2 ] = arrays
193201 const concreteKeys = Array . isArray ( keys )
You can’t perform that action at this time.
0 commit comments