Skip to content

Commit 730a43d

Browse files
Multiple sandboxes found - Execute operation for first only (#561)
* The fix sorts all sandboxes by creation date (latest on top), calls out a warning on the first sandbox but executes the operation anyway and throws an error for subsequent sandboxes. * typo --------- Co-authored-by: Tobias Lohr <tlohr@salesforce.com>
1 parent 326e4bf commit 730a43d

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

lib/sandbox.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,25 @@ function lookupSandbox(spec, callback) {
515515
return;
516516
}
517517

518-
callback(new Error('Found ' + filtered.length + ' matching sandboxes.'));
518+
// multiple sandboxes should be the very exception and in those cases the most recently created
519+
// sandbox should be addressed with the requested operation. in all other cases the operation should
520+
// be skipped and error messages returned.
521+
filtered = filtered.sort( function sortFilteredSandboxesDesc(sb1, sb2) {
522+
return sb1.createdAt.localeCompare(sb2.createdAt) * -1;
523+
});
524+
525+
var sandboxIndex = 1;
526+
filtered.forEach( function(sbxInfo) {
527+
if (sandboxIndex === 1) {
528+
console.warn('More than one sandbox found. Executing the operation only for '
529+
+ 'the sandbox that has been created on ' + sbxInfo.createdAt);
530+
callback(undefined , sbxInfo);
531+
} else {
532+
callback(new Error('Ambigious sandbox ID. Skipping operation for the sandbox that has '
533+
+ 'been created on ' + sbxInfo.createdAt));
534+
}
535+
sandboxIndex++;
536+
});
519537
});
520538
}
521539

0 commit comments

Comments
 (0)