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' ;
2122
2223Messages . importMessagesDirectoryFromMetaUrl ( import . meta. url ) ;
2324const messages = Messages . loadMessages ( '@salesforce/plugin-org' , 'resume_scratch' ) ;
2425
25- export default class EnvResumeScratch extends SfCommand < ScratchCreateResponse > {
26+ export default class OrgResumeScratch extends SfCommand < ScratchCreateResponse > {
2627 public static readonly summary = messages . getMessage ( 'summary' ) ;
2728 public static readonly description = messages . getMessage ( 'description' ) ;
2829 public static readonly examples = messages . getMessages ( 'examples' ) ;
@@ -45,7 +46,7 @@ export default class EnvResumeScratch extends SfCommand<ScratchCreateResponse> {
4546 } ;
4647
4748 public async run ( ) : Promise < ScratchCreateResponse > {
48- const { flags } = await this . parse ( EnvResumeScratch ) ;
49+ const { flags } = await this . parse ( OrgResumeScratch ) ;
4950 const cache = await ScratchOrgCache . create ( ) ;
5051 const lifecycle = Lifecycle . getInstance ( ) ;
5152
@@ -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,20 @@ 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 instanceof Error && e . 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+ }
7585 }
7686}
0 commit comments