Skip to content

Commit

Permalink
The fix sorts all sandboxes by creation date (latest on top), calls o…
Browse files Browse the repository at this point in the history
…ut a warning on the first sandbox but executes the operation anyway and throws an error for subsequent sandboxes.
  • Loading branch information
kdomachowski committed Feb 2, 2024
1 parent 7eacb62 commit 3013945
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,25 @@ function lookupSandbox(spec, callback) {
return;
}

callback(new Error('Found ' + filtered.length + ' matching sandboxes.'));
// multiple sandboxes should be the very exception and in those cases the most recently created
// sandbox should be addressed with the requested operation. in all other cases the operation should
// be skipped and error messages returned.
filtered = filtered.sort( function sortFilteredSandboxesDesc(sb1, sb2) {
return sb1.createdAt.localeCompare(sb2.createdAt) * -1;
});

var sandboxIndex = 1;
filtered.forEach( function(sbxInfo) {
if (sandboxIndex === 1) {
console.warn('More than one sandbox found. Executing the operation only for '
+ 'the sandbox tha has been created on ' + sbxInfo.createdAt);
callback(undefined , sbxInfo);
} else {
callback(new Error('Ambigious sandbox ID. Skipping operation for the sandbox that has '
+ 'been created on ' + sbxInfo.createdAt));
}
sandboxIndex++;
});
});
}

Expand Down

0 comments on commit 3013945

Please sign in to comment.