Skip to content

Commit 7d41f5f

Browse files
fix: check cache keys, add helpful error when a miss happens
1 parent 3007e19 commit 7d41f5f

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

messages/resume_scratch.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Resume the creation of an incomplete scratch org.
44

55
# description
66

7-
When the original "<%= config.bin %> org create scratch" command either times out or is run with the --async flag, it displays a job ID.
7+
When the original "<%= config.bin %> org create scratch" command either times out or is run with the --async flag, it
8+
displays a job ID.
89

9-
Run this command by either passing it a job ID or using the --use-most-recent flag to specify the most recent incomplete scratch org.
10+
Run this command by either passing it a job ID or using the --use-most-recent flag to specify the most recent incomplete
11+
scratch org.
1012

1113
# examples
1214

@@ -36,6 +38,10 @@ Use the job ID of the most recent incomplete scratch org.
3638

3739
There are no recent job IDs (ScratchOrgInfo requests) in your cache. Maybe it completed or already resumed?
3840

41+
# error.jobIdMismatch
42+
43+
There are no recent job IDs (ScratchOrgInfo requests) in your cache that match %s. Maybe it completed?
44+
3945
# success
4046

4147
Your scratch org is ready.

src/commands/org/resume/scratch.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
import { strict as assert } from 'node:assert';
99

10-
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
10+
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
1111
import {
12+
Lifecycle,
1213
Messages,
13-
scratchOrgResume,
1414
ScratchOrgCache,
15-
Lifecycle,
1615
ScratchOrgLifecycleEvent,
1716
scratchOrgLifecycleEventName,
17+
scratchOrgResume,
18+
SfError,
1819
} from '@salesforce/core';
1920
import { ScratchCreateResponse } from '../../../shared/orgTypes.js';
2021
import { buildStatus } from '../../../shared/scratchOrgOutput.js';
@@ -54,7 +55,7 @@ export default class EnvResumeScratch extends SfCommand<ScratchCreateResponse> {
5455

5556
// oclif doesn't know that the exactlyOne flag will ensure that one of these is set, and there we definitely have a jobID.
5657
assert(jobId);
57-
const { hubBaseUrl } = cache.get(jobId);
58+
const hubBaseUrl = cache.get(jobId)?.hubBaseUrl;
5859
let lastStatus: string | undefined;
5960

6061
lifecycle.on<ScratchOrgLifecycleEvent>(scratchOrgLifecycleEventName, async (data): Promise<void> => {
@@ -66,11 +67,21 @@ export default class EnvResumeScratch extends SfCommand<ScratchCreateResponse> {
6667
this.log();
6768
this.spinner.start('Creating Scratch Org');
6869

69-
const { username, scratchOrgInfo, authFields, warnings } = await scratchOrgResume(jobId);
70-
this.spinner.stop(lastStatus);
70+
try {
71+
const { username, scratchOrgInfo, authFields, warnings } = await scratchOrgResume(jobId);
72+
this.spinner.stop(lastStatus);
7173

72-
this.log();
73-
this.logSuccess(messages.getMessage('success'));
74-
return { username, scratchOrgInfo, authFields, warnings, orgId: authFields?.orgId };
74+
this.log();
75+
this.logSuccess(messages.getMessage('success'));
76+
return { username, scratchOrgInfo, authFields, warnings, orgId: authFields?.orgId };
77+
} catch (e) {
78+
if (cache.keys() && (e as Error).name === 'CacheMissError') {
79+
// we have something in the cache, but it didn't match what the user passed in
80+
throw messages.createError('error.jobIdMismatch', [jobId]);
81+
} else {
82+
throw SfError.wrap(e);
83+
}
84+
return {} as ScratchCreateResponse;
85+
}
7586
}
7687
}

0 commit comments

Comments
 (0)