Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions messages/delete_sandbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ Ensure the CLI has authenticated with the sandbox's production org.
# error.missingUsername

Unable to determine the username of the org to delete. Specify the username with the --target-org | -o flag.

# error.insufficientAccess

You don't have permission to delete this sandbox. Ask your Salesforce admin to grant you the "Manage Sandboxes" system permission on your profile or a permission set in the production org.
6 changes: 6 additions & 0 deletions src/commands/org/delete/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ export default class DeleteSandbox extends SfCommand<SandboxDeleteResponse> {
this.logSuccess(messages.getMessage('success.Idempotent', [username]));
} else if (e instanceof Error && e.name === 'SandboxNotFound') {
this.logSuccess(messages.getMessage('success.Idempotent', [username]));
} else if (
e instanceof Error &&
'errorCode' in e &&
(e as { errorCode: string }).errorCode === 'INSUFFICIENT_ACCESS_OR_READONLY'
) {
throw messages.createError('error.insufficientAccess');
} else {
throw e;
}
Expand Down
17 changes: 17 additions & 0 deletions test/unit/org/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ describe('org delete', () => {
JSON.stringify(sfCommandUxStubs.logSuccess.getCalls().flatMap((call) => call.args))
).to.deep.include(sbxOrgMessages.getMessage('success.Idempotent', [testOrg.username]));
});

it('will throw a clean SfError when the user lacks Manage Sandboxes permission', async () => {
$$.SANDBOX.stub(SandboxAccessor.prototype, 'hasFile').resolves(true);
orgDeleteStub.restore();
const insufficientAccessError = Object.assign(new Error('INSUFFICIENT_ACCESS_OR_READONLY'), {
errorCode: 'INSUFFICIENT_ACCESS_OR_READONLY',
});
$$.SANDBOX.stub(Org.prototype, 'delete').throws(insufficientAccessError);
try {
await DeleteSandbox.run(['--no-prompt', '--target-org', testOrg.username]);
expect.fail('should have thrown InsufficientAccessError');
} catch (e) {
const err = e as SfError;
expect(err.name).to.equal('InsufficientAccessError');
expect(err.message).to.equal(sbxOrgMessages.getMessage('error.insufficientAccess'));
}
});
});

describe('scratch', () => {
Expand Down