Skip to content

Commit

Permalink
refactor(CLI): Report credentials source in modern error output
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 19, 2021
1 parent a3edecf commit b4ff87d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
40 changes: 33 additions & 7 deletions lib/cli/handle-error.js
Expand Up @@ -6,6 +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 { getDashboardProvidersUrl } = require('@serverless/dashboard-plugin/lib/dashboard');
const { style, writeText, legacy, log } = require('@serverless/utils/log');
const slsVersion = require('./../../package').version;
const { logWarning } = require('../classes/Error');
Expand Down Expand Up @@ -145,15 +146,40 @@ module.exports = async (exception, options = {}) => {
}
})();

writeText(
style.aside(
`Environment: ${platform}, node ${nodeVersion}, framework ${slsVersion}${installationModePostfix}, plugin ${sfeVersion}, SDK ${platformClientVersion}`,
'Docs: docs.serverless.com',
'Support: forum.serverless.com',
'Bugs: github.com/serverless/serverless/issues'
)
const detailsTextTokens = [
`Environment: ${platform}, node ${nodeVersion}, framework ${slsVersion}${installationModePostfix}, plugin ${sfeVersion}, SDK ${platformClientVersion}`,
];

if (serverless && serverless.service.provider.name === 'aws') {
const credentials = serverless.getProvider('aws').cachedCredentials;
if (credentials) {
if (credentials.dashboardProviderAlias) {
detailsTextTokens.push(
`Credentials: Serverless Dashboard, "${
credentials.dashboardProviderAlias
}" provider (${getDashboardProvidersUrl(serverless.pluginManager.dashboardPlugin)})`
);
} else if (credentials.credentials) {
if (credentials.credentials.profile) {
detailsTextTokens.push(
`Credentials: Local, "${credentials.credentials.profile}" profile`
);
} else {
// The only alternative here are credentials from environment variables
detailsTextTokens.push('Credentials: Local, environment variables');
}
}
}
}

detailsTextTokens.push(
'Docs: docs.serverless.com',
'Support: forum.serverless.com',
'Bugs: github.com/serverless/serverless/issues'
);

writeText(style.aside(...detailsTextTokens));

// TODO: Ideally after migrating to new logger complete this strip should not be needed
// (it can be removed after we clear all chalk error message decorations from internals)
const errorMsg =
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@serverless/cli": "^1.5.2",
"@serverless/components": "^3.17.1",
"@serverless/dashboard-plugin": "^5.4.8",
"@serverless/dashboard-plugin": "^5.5.0",
"@serverless/platform-client": "^4.3.0",
"@serverless/utils": "^5.18.0",
"ajv": "^6.12.6",
Expand Down

0 comments on commit b4ff87d

Please sign in to comment.