@@ -15,6 +15,7 @@ import { ToolkitError } from '../errors'
1515import { SamCliSettings } from './cli/samCliSettings'
1616import { SamCliInfoInvocation } from './cli/samCliInfo'
1717import { parse } from 'semver'
18+ import { ChildProcessResult } from '../utilities/processUtils'
1819
1920/**
2021 * @description determines the root directory of the project given Template Item
@@ -93,12 +94,27 @@ export function getSamCliErrorMessage(stderr: string): string {
9394 return lines [ lines . length - 1 ]
9495}
9596
97+ export function getErrorCode ( error : unknown ) : string | undefined {
98+ return error instanceof ToolkitError ? error . code : undefined
99+ }
100+
101+ export function throwIfErrorMatches ( result : ChildProcessResult ) {
102+ const errorMessage = getSamCliErrorMessage ( result . stderr )
103+ for ( const errorType in SamCliErrorTypes ) {
104+ if ( errorMessage . includes ( SamCliErrorTypes [ errorType as keyof typeof SamCliErrorTypes ] ) ) {
105+ throw ToolkitError . chain ( result . error , errorMessage , {
106+ code : errorType ,
107+ } )
108+ }
109+ }
110+ }
111+
96112export enum SamCliErrorTypes {
97113 DockerUnreachable = 'Docker is unreachable.' ,
98114 ResolveS3AndS3Set = 'Cannot use both --resolve-s3 and --s3-bucket parameters in non-guided deployments.' ,
99115 DeployStackStatusMissing = 'Was not able to find a stack with the name:' ,
100116 DeployStackOutPutFailed = 'Failed to get outputs from stack' ,
101117 DeployBucketRequired = 'Templates with a size greater than 51,200 bytes must be deployed via an S3 Bucket.' ,
102- NoUpdate = 'is up to date' ,
118+ NoUpdateExitCode = 'is up to date' ,
103119 ChangeSetEmpty = 'No changes to deploy. Stack is up to date' ,
104120}
0 commit comments