| 318 | } |
| 319 | |
| 320 | async function doProvision(options: ProvisionOptions, providedIdLabels: string[] | undefined) { |
| 321 | const disposables: (() => Promise<unknown> | undefined)[] = []; |
| 322 | const dispose = async () => { |
| 323 | await Promise.all(disposables.map(d => d())); |
| 324 | }; |
| 325 | try { |
| 326 | const result = await launch(options, providedIdLabels, disposables); |
| 327 | return { |
| 328 | outcome: 'success' as 'success', |
| 329 | dispose, |
| 330 | ...result, |
| 331 | }; |
| 332 | } catch (originalError) { |
| 333 | const originalStack = originalError?.stack; |
| 334 | const err = originalError instanceof ContainerError ? originalError : new ContainerError({ |
| 335 | description: 'An error occurred setting up the container.', |
| 336 | originalError |
| 337 | }); |
| 338 | if (originalStack) { |
| 339 | console.error(originalStack); |
| 340 | } |
| 341 | return { |
| 342 | outcome: 'error' as 'error', |
| 343 | message: err.message, |
| 344 | description: err.description, |
| 345 | containerId: err.containerId, |
| 346 | disallowedFeatureId: err.data.disallowedFeatureId, |
| 347 | didStopContainer: err.data.didStopContainer, |
| 348 | learnMoreUrl: err.data.learnMoreUrl, |
| 349 | dispose, |
| 350 | }; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | function setUpOptions(y: Argv) { |
| 355 | return y.options({ |