Skip to content

Commit 3310249

Browse files
committed
fix(Variables): Ensure proper resolution in case of errors
1 parent 2984adb commit 3310249

6 files changed

Lines changed: 11 additions & 6 deletions

File tree

lib/configuration/variables/sources/instance-dependent/get-cf.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ module.exports = (serverlessInstance) => {
4141
{ useCache: true, region: params && params[0] }
4242
);
4343
} catch (error) {
44-
if (error.code === 'ValidationError' && error.message.includes('does not exist')) {
44+
if (
45+
error.code === 'AWS_CLOUD_FORMATION_DESCRIBE_STACKS_VALIDATION_ERROR' &&
46+
error.message.includes('does not exist')
47+
) {
4548
return null;
4649
}
4750
throw error;

lib/configuration/variables/sources/instance-dependent/get-s3.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ module.exports = (serverlessInstance) => {
3535
.getProvider('aws')
3636
.request('S3', 'getObject', { Bucket: bucketName, Key: key }, { useCache: true });
3737
} catch (error) {
38-
if (error.code === 'NoSuchKey') return null;
38+
// Check for normalized error code instead of native one
39+
if (error.code === 'AWS_S3_GET_OBJECT_NO_SUCH_KEY') return null;
3940
throw error;
4041
}
4142
})();

lib/configuration/variables/sources/instance-dependent/get-ssm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ module.exports = (serverlessInstance) => {
6363
{ useCache: true, region }
6464
);
6565
} catch (error) {
66-
if (error.code === 'ParameterNotFound') return null;
66+
// Check for normalized error code instead of native one
67+
if (error.code === 'AWS_S_S_M_GET_PARAMETER_PARAMETER_NOT_FOUND') return null;
6768
throw error;
6869
}
6970
})();

test/unit/lib/configuration/variables/sources/instance-dependent/get-cf.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-c
4141
}
4242
if (StackName === 'notExisting') {
4343
throw Object.assign(new Error('Stack with id not-existing does not exist'), {
44-
code: 'ValidationError',
44+
code: 'AWS_CLOUD_FORMATION_DESCRIBE_STACKS_VALIDATION_ERROR',
4545
});
4646
}
4747
throw new Error('Unexpected call');

test/unit/lib/configuration/variables/sources/instance-dependent/get-s3.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
3434
if (Bucket === 'existing') {
3535
if (Key === 'someKey') return { Body: 'foo' };
3636
throw Object.assign(new Error('The specified key does not exist.'), {
37-
code: 'NoSuchKey',
37+
code: 'AWS_S3_GET_OBJECT_NO_SUCH_KEY',
3838
});
3939
}
4040
throw Object.assign(new Error('The specified bucket does not exist.'), {

test/unit/lib/configuration/variables/sources/instance-dependent/get-ssm.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('test/unit/lib/configuration/variables/sources/instance-dependent/get-s
5656
'(ParameterNotFound) when referencing Secrets Manager'
5757
),
5858
{
59-
code: 'ParameterNotFound',
59+
code: 'AWS_S_S_M_GET_PARAMETER_PARAMETER_NOT_FOUND',
6060
}
6161
);
6262
}

0 commit comments

Comments
 (0)