serverless/lib/configuration/variables/eventually-report-resolution-errors.js
Mariusz Nowak 5b54ed2e26 refactor: Drop old variables engine related deprecation
Old variables engine will be removed with next major, so there's no point to communicate breaking changes that were supposed to introduced if it was to stay
2021-07-06 12:03:51 +02:00

47 lines
1.5 KiB
JavaScript

'use strict';
const path = require('path');
const log = require('@serverless/utils/log');
const ServerlessError = require('../../serverless-error');
const resolveCliInput = require('../../cli/resolve-input');
const logDeprecation = require('../../utils/logDeprecation');
module.exports = (configurationPath, configuration, variablesMeta) => {
const resolutionErrors = new Set(
Array.from(variablesMeta.values(), ({ error }) => error).filter(Boolean)
);
if (!resolutionErrors.size) return false;
if (resolveCliInput().isHelpRequest) {
log(
'Resolution of service configuration failed when resolving variables: ' +
`${Array.from(resolutionErrors, (error) => `\n - ${error.message}`)}\n`,
{ color: 'orange' }
);
} else {
if (configuration.variablesResolutionMode) {
throw new ServerlessError(
`Cannot resolve ${path.basename(
configurationPath
)}: Variables resolution errored with:${Array.from(
resolutionErrors,
(error) => `\n - ${error.message}`
)}`,
'VARIABLES_RESOLUTION_ERROR'
);
}
logDeprecation(
'NEW_VARIABLES_RESOLVER',
'Variables resolver reports following resolution errors:' +
`${Array.from(resolutionErrors, (error) => `\n - ${error.message}`)}\n` +
'From a next major this will be communicated with a thrown error.\n' +
'Set "variablesResolutionMode: 20210326" in your service config, ' +
'to adapt to new behavior now',
{ serviceConfig: configuration }
);
}
return true;
};