Skip to content

Commit 6adaa9f

Browse files
committed
refactor: Ensure codes for user errors
1 parent 18a9b2b commit 6adaa9f

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

scripts/serverless.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ const processSpanPromise = (async () => {
7171
// Abort if command is not supported in this environment
7272
if (commandSchema && commandSchema.isHidden && commandSchema.noSupportNotice) {
7373
throw new ServerlessError(
74-
`Cannot run \`${command}\` command: ${commandSchema.noSupportNotice}`
74+
`Cannot run \`${command}\` command: ${commandSchema.noSupportNotice}`,
75+
'NOT_SUPPORTED_COMMAND'
7576
);
7677
}
7778

@@ -101,7 +102,8 @@ const processSpanPromise = (async () => {
101102
`Cannot resolve ${path.basename(
102103
configurationPath
103104
)}: "${humanizedPropertyPath}" property is not accessible ` +
104-
'(configured behind variables which cannot be resolved at this stage)'
105+
'(configured behind variables which cannot be resolved at this stage)',
106+
'INACCESSIBLE_CONFIGURATION_PROPERTY'
105107
);
106108
}
107109
logDeprecation(
@@ -165,7 +167,8 @@ const processSpanPromise = (async () => {
165167
`Cannot resolve ${path.basename(
166168
configurationPath
167169
)}: "variableSyntax" is not supported with new variables resolver. ` +
168-
'Please drop this setting'
170+
'Please drop this setting',
171+
'UNSUPPORTED_VARIABLE_SYNTAX_CONFIGURATION'
169172
);
170173
}
171174
logDeprecation(
@@ -563,6 +566,7 @@ const processSpanPromise = (async () => {
563566
'Invalid "configurationVariablesSources" ' +
564567
`configuration on "${pluginName}", expected object, got: %v"`,
565568
Error: ServerlessError,
569+
errorCode: 'INVALID_VARIABLE_SOURCES_CONFIGURATION',
566570
});
567571

568572
for (const [sourceName, sourceConfig] of Object.entries(
@@ -572,7 +576,8 @@ const processSpanPromise = (async () => {
572576
throw new ServerlessError(
573577
`Cannot add "${sourceName}" configuration variable source ` +
574578
`(through "${pluginName}" plugin) as resolution rules ` +
575-
'for this source name are already configured'
579+
'for this source name are already configured',
580+
'DUPLICATE_VARIABLE_SOURCE_CONFIGURATION'
576581
);
577582
}
578583
ensurePlainFunction(
@@ -581,12 +586,14 @@ const processSpanPromise = (async () => {
581586
`Invalid "configurationVariablesSources.${sourceName}" ` +
582587
`configuration on "${pluginName}", expected object, got: %v"`,
583588
Error: ServerlessError,
589+
errorCode: 'INVALID_VARIABLE_SOURCE_CONFIGURATION',
584590
}).resolve,
585591
{
586592
errorMessage:
587593
`Invalid "configurationVariablesSources.${sourceName}.resolve" ` +
588594
`value on "${pluginName}", expected function, got: %v"`,
589595
Error: ServerlessError,
596+
errorCode: 'INVALID_VARIABLE_SOURCE_RESOLVER_CONFIGURATION',
590597
}
591598
);
592599

0 commit comments

Comments
 (0)