Skip to content

Commit

Permalink
refactor(CLI): Adapt logWarning to modern logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 11, 2021
1 parent 43f9fae commit d43298d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
15 changes: 6 additions & 9 deletions lib/classes/Error.js
Expand Up @@ -2,26 +2,23 @@

const chalk = require('chalk');
const ServerlessError = require('../serverless-error');

const consoleLog = (message) => {
process.stdout.write(`${message}\n`);
};
const { legacy } = require('@serverless/utils/log');

const writeMessage = (title, message) => {
let line = '';
while (line.length < 56 - title.length) {
line = `${line}-`;
}

consoleLog(' ');
consoleLog(chalk.yellow(` ${title} ${line}`));
consoleLog(' ');
legacy.consoleLog(' ');
legacy.consoleLog(chalk.yellow(` ${title} ${line}`));
legacy.consoleLog(' ');

if (message) {
consoleLog(` ${message.split('\n').join('\n ')}`);
legacy.consoleLog(` ${message.split('\n').join('\n ')}`);
}

consoleLog(' ');
legacy.consoleLog(' ');
};

module.exports.ServerlessError = ServerlessError;
Expand Down
3 changes: 3 additions & 0 deletions lib/classes/Service.js
Expand Up @@ -70,6 +70,9 @@ class Service {
logWarning(
'Configured "frameworkVersion" does not represent a valid semver version range, version validation is skipped'
);
log.warning(
'Configured "frameworkVersion" does not represent a valid semver version range, version validation is skipped'
);
ymlVersion = null;
}
if (!this.isLocallyInstalled && !ymlVersion) {
Expand Down
7 changes: 7 additions & 0 deletions lib/classes/Variables.js
Expand Up @@ -10,6 +10,7 @@ const fse = require('fs-extra');
const logWarning = require('./Error').logWarning;
const PromiseTracker = require('./PromiseTracker');
const ServerlessError = require('../serverless-error');
const { log } = require('@serverless/utils/log');

const resolvedValuesWeak = new WeakSet();

Expand Down Expand Up @@ -855,6 +856,9 @@ class Variables {
logWarning(
`Cannot split SSM parameter '${param}' of type '${type}'. Must be 'StringList'.`
);
log.warning(
`Cannot split SSM parameter '${param}' of type '${type}'. Must be 'StringList'.`
);
}
return plainText;
},
Expand Down Expand Up @@ -1007,6 +1011,9 @@ class Variables {
logWarning(
`A valid ${varType} to satisfy the declaration '${variableString}' could not be found.`
);
log.warning(
`A valid ${varType} to satisfy the declaration '${variableString}' could not be found.`
);
}
}

Expand Down
11 changes: 11 additions & 0 deletions lib/cli/commands-schema/resolve-final.js
Expand Up @@ -9,6 +9,7 @@ const awsServiceCommands = require('./aws-service');
const serviceOptions = require('./common-options/service');
const awsServiceOptions = require('./common-options/aws-service');
const { logWarning } = require('../../classes/Error');
const { log } = require('@serverless/utils/log');

const deprecatedEventPattern = /^deprecated#(.*?)(?:->(.*?))?$/;

Expand Down Expand Up @@ -122,6 +123,16 @@ module.exports = (loadedPlugins, { providerName }) => {
).join('\n - ')}\n\n` +
'Please report this issue in plugin issue tracker.'
);
log.warning(
'CLI options definitions were upgraded with "type" property (which could be one of "string", "boolean", "multiple"). ' +
'Plugins listed below do not predefine type for introduced options:\n' +
` - ${Array.from(
missingOptionTypes,
([plugin, optionNames]) =>
`${plugin.constructor.name} for "${Array.from(optionNames).join('", "')}"`
).join('\n - ')}\n\n` +
'Please report this issue in issue tracker of the corresponding plugin.'
);
}

return commands;
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/handle-error.js
Expand Up @@ -6,7 +6,7 @@ const chalk = require('chalk');
const stripAnsi = require('strip-ansi');
const sfeVersion = require('@serverless/dashboard-plugin/package.json').version;
const { platformClientVersion } = require('@serverless/dashboard-plugin');
const { style, writeText, legacy } = require('@serverless/utils/log');
const { style, writeText, legacy, log } = require('@serverless/utils/log');
const slsVersion = require('./../../package').version;
const { logWarning } = require('../classes/Error');
const isStandaloneExecutable = require('../utils/isStandaloneExecutable');
Expand Down Expand Up @@ -98,6 +98,7 @@ module.exports = async (exception, options = {}) => {
// It can happen e.g. during "plugin uninstall" command, where "serverless" originally
// installed a as peer dependency was removed
logWarning('Could not resolve path to locally installed error handler');
log.warning('Could not resolve path to locally installed error handler');
return null;
}
}
Expand Down
13 changes: 13 additions & 0 deletions lib/plugins/aws/package/compile/events/httpApi.js
Expand Up @@ -4,6 +4,7 @@ const _ = require('lodash');
const d = require('d');
const memoizee = require('memoizee');
const memoizeeMethods = require('memoizee/methods');
const { log } = require('@serverless/utils/log');
const ServerlessError = require('../../../../../serverless-error');
const { logWarning } = require('../../../../../classes/Error');
const resolveLambdaTarget = require('../../../utils/resolveLambdaTarget');
Expand Down Expand Up @@ -617,13 +618,25 @@ Object.defineProperties(
'This may introduce a situation where endpoint times out ' +
'for a succesful lambda invocation.'
);
log.warning(
`Function (${functionName}) timeout setting (${functionTimeout}) is greater than ` +
'maximum allowed timeout for HTTP API endpoint (29s). ' +
'This may introduce a situation where endpoint times out ' +
'for a succesful lambda invocation.'
);
} else if (functionTimeout === 29) {
logWarning(
`Function (${functionName}) timeout setting (${functionTimeout}) may not provide ` +
'enough room to process an HTTP API request (of which timeout is limited to 29s). ' +
'This may introduce a situation where endpoint times out ' +
'for a succesful lambda invocation.'
);
log.warning(
`Function (${functionName}) timeout setting (${functionTimeout}) may not provide ` +
'enough room to process an HTTP API request (of which timeout is limited to 29s). ' +
'This may introduce a situation where endpoint times out ' +
'for a succesful lambda invocation.'
);
}
// Ensure endpoint has slightly larger timeout than a function,
// It's a margin needed for some side processing time on AWS side.
Expand Down

0 comments on commit d43298d

Please sign in to comment.