77
88import { 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' ;
1111import {
12+ Lifecycle ,
1213 Messages ,
13- scratchOrgResume ,
1414 ScratchOrgCache ,
15- Lifecycle ,
1615 ScratchOrgLifecycleEvent ,
1716 scratchOrgLifecycleEventName ,
17+ scratchOrgResume ,
18+ SfError ,
1819} from '@salesforce/core' ;
1920import { ScratchCreateResponse } from '../../../shared/orgTypes.js' ;
2021import { 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