Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple sandboxes found - Execute operation for first only #561

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 that 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
Loading