mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
refactor: Add code to ServerlessError in lib/configuration
This commit is contained in:
parent
28c5af47f4
commit
395bdc8b23
@ -37,7 +37,7 @@ const resolveTsNode = async (serviceDir) => {
|
||||
return require.resolve(`${String(stdoutBuffer).trim()}/ts-node`);
|
||||
} catch (globalDepError) {
|
||||
if (globalDepError.code !== 'MODULE_NOT_FOUND') throw globalDepError;
|
||||
throw new ServerlessError('"ts-node" not found');
|
||||
throw new ServerlessError('"ts-node" not found', 'TS_NODE_NOT_FOUND');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ module.exports = (configuration) => {
|
||||
{
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Invalid service configuration: "provider.name" property is missing',
|
||||
errorCode: 'INVALID_CONFIGURATION_PROVIDER_NAME_MISSING',
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
|
||||
@ -14,6 +14,7 @@ module.exports = {
|
||||
address = ensureString(address, {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument in variable "env" source: %v',
|
||||
errorCode: 'INVALID_ENV_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
|
||||
return { value: process.env[address] || null, isPending: !isSourceFulfilled };
|
||||
|
||||
@ -33,6 +33,7 @@ module.exports = {
|
||||
ensureString(params[0], {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string path argument in variable "file" source: %v',
|
||||
errorCode: 'INVALID_FILE_SOURCE_PATH_ARGUMENT',
|
||||
})
|
||||
);
|
||||
if (!filePath.startsWith(`${serviceDir}${path.sep}`)) {
|
||||
@ -45,6 +46,7 @@ module.exports = {
|
||||
address = ensureString(address, {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument for variable "file" source: %v',
|
||||
errorCode: 'INVALID_FILE_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ module.exports = (serverlessInstance) => {
|
||||
address = ensureString(address, {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument in variable "cf" source: %v',
|
||||
errorCode: 'INVALID_CF_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
const separatorIndex = address.indexOf('.');
|
||||
if (separatorIndex === -1) {
|
||||
|
||||
@ -16,6 +16,7 @@ module.exports = (serverlessInstance) => {
|
||||
address = ensureString(address, {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument in variable "s3" source: %v',
|
||||
errorCode: 'INVALID_S3_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
const separatorIndex = address.indexOf('/');
|
||||
if (separatorIndex === -1) {
|
||||
|
||||
@ -15,6 +15,7 @@ module.exports = (serverlessInstance) => {
|
||||
address = ensureString(address, {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument in variable "sls" source: %v',
|
||||
errorCode: 'INVALID_SLS_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
|
||||
switch (address) {
|
||||
|
||||
@ -19,6 +19,7 @@ module.exports = (serverlessInstance) => {
|
||||
address = ensureString(address, {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument in variable "ssm" source: %v',
|
||||
errorCode: 'INVALID_SSM_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
const region = !params || !params[0] || params[0] === 'raw' ? undefined : params[0];
|
||||
const shouldReturnRawValue = params && (params[0] === 'raw' || params[1] === 'raw');
|
||||
|
||||
@ -9,6 +9,7 @@ module.exports = {
|
||||
isOptional: true,
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string address argument in variable "opt" source: %v',
|
||||
errorCode: 'INVALID_OPT_SOURCE_ADDRESS_ARGUMENT',
|
||||
});
|
||||
if (!isSourceFulfilled) {
|
||||
if (address == null) return { value: null, isPending: true };
|
||||
|
||||
@ -15,6 +15,7 @@ module.exports = {
|
||||
const stringValue = ensureString(params[0], {
|
||||
Error: ServerlessError,
|
||||
errorMessage: 'Non-string "strToBool" input:. Received: %v',
|
||||
errorCode: 'INVALID_STR_TO_BOOL_SOURCE_VALUE',
|
||||
}).trim();
|
||||
|
||||
if (trueStrings.has(stringValue)) return { value: true };
|
||||
|
||||
@ -3,8 +3,9 @@
|
||||
const { expect } = require('chai');
|
||||
|
||||
const resolveProviderName = require('../../../../lib/configuration/resolve-provider-name');
|
||||
const ServerlessError = require('../../../../lib/serverless-error');
|
||||
|
||||
describe('test/unit/lib/configuration/resolve-provider.name.test.js', () => {
|
||||
describe('test/unit/lib/configuration/resolve-provider-name.test.js', () => {
|
||||
it('should read name from "provider"', () => {
|
||||
expect(resolveProviderName({ provider: 'foo' })).to.equal('foo');
|
||||
});
|
||||
@ -12,14 +13,18 @@ describe('test/unit/lib/configuration/resolve-provider.name.test.js', () => {
|
||||
expect(resolveProviderName({ provider: { name: 'foo' } })).to.equal('foo');
|
||||
});
|
||||
it('should reject missing "provider.name"', () => {
|
||||
expect(() => resolveProviderName({ provider: {} })).to.throw('Invalid service configuration');
|
||||
expect(() => resolveProviderName({ provider: {} }))
|
||||
.to.throw(ServerlessError)
|
||||
.with.property('code', 'INVALID_CONFIGURATION_PROVIDER_NAME_MISSING');
|
||||
});
|
||||
it('should reject invalid "provider.name"', () => {
|
||||
expect(() => resolveProviderName({ provider: { name: {} } })).to.throw(
|
||||
'Invalid service configuration'
|
||||
);
|
||||
expect(() => resolveProviderName({ provider: { name: {} } }))
|
||||
.to.throw(ServerlessError)
|
||||
.with.property('code', 'INVALID_CONFIGURATION_PROVIDER_NAME_MISSING');
|
||||
});
|
||||
it('should reject missing "provider"', () => {
|
||||
expect(() => resolveProviderName({})).to.throw('Invalid service configuration');
|
||||
expect(() => resolveProviderName({}))
|
||||
.to.throw(ServerlessError)
|
||||
.with.property('code', 'INVALID_CONFIGURATION_PROVIDER_NAME_MISSING');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user