Skip to content

Commit 1102a98

Browse files
committed
feat(deploy): improve output for failed deployments (#24)
fix #24
1 parent c84a85d commit 1102a98

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/commands/deploy.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import { Arguments, Argv } from 'yargs';
1212
import { checkConfigForCredentials } from '../checks/check-credentials';
1313
import checkProjectStructure from '../checks/project-structure';
1414
import { printConfigInfo, printDeployedResources } from '../printers/deploy';
15+
import { errorMessage } from '../printers/utils';
1516
import {
17+
ApiErrorResponse,
1618
getFunctionServiceSid,
1719
HttpError,
1820
saveLatestDeploymentData,
@@ -143,10 +145,11 @@ function handleError(
143145
config: DeployLocalProjectConfig
144146
) {
145147
log('%O', err);
148+
spinner.fail('Failed Deployment');
146149
if (err.name === 'conflicting-servicename') {
147-
spinner.fail(err.message);
148-
console.log(stripIndent`
150+
const messageBody = stripIndent`
149151
Here are a few ways to solve this problem:
152+
150153
- Rename your project in the package.json "name" property
151154
- Pass an explicit name to your deployment
152155
> ${flags.$0} deploy -n my-new-service-name
@@ -156,11 +159,20 @@ function handleError(
156159
> ${flags.$0} deploy --override-existing-project
157160
- Run deployment in force mode
158161
> ${flags.$0} deploy --force
159-
`);
162+
`;
163+
console.error(errorMessage(err.message, messageBody));
160164
} else if (err.name === 'HTTPError') {
161-
spinner.fail((err as HttpError).body.message);
165+
const responseBody = JSON.parse(
166+
(err as HttpError).body
167+
) as ApiErrorResponse;
168+
const messageBody = stripIndent`
169+
${responseBody.message}
170+
171+
More info: ${responseBody.more_info}
172+
`;
173+
console.error(errorMessage('', messageBody));
162174
} else {
163-
spinner.fail(err.message);
175+
console.error(err.message);
164176
}
165177
process.exit(1);
166178
}

src/printers/utils.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ export function borderLeft(text: string, color: string): string {
2323
.join('\n');
2424
}
2525

26+
const wrapText = (text: string) =>
27+
wrapAnsi(text, size.width - 5, { trim: false });
28+
2629
export function importantMessage(
2730
label: string,
2831
color: string,
2932
title: string,
3033
body: string
3134
) {
3235
label = chalk.keyword(color)(label);
33-
title = chalk.bold.underline(`${label} ${chalk.bold(title)}`);
34-
body = wrapAnsi(body, size.width - 5);
36+
title = wrapText(chalk.bold.underline(`${label} ${chalk.bold(title)}`));
37+
body = wrapText(body);
3538

3639
return '\n' + borderLeft(`${title}\n\n${chalk.dim(body)}`, color) + '\n';
3740
}

src/serverless-api/utils.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ const log = debug('twilio-run:internal:utils');
66

77
export interface HttpError extends Error {
88
name: 'HTTPError';
9-
body: {
10-
message: string;
11-
};
9+
body: string;
1210
}
1311

12+
export type ApiErrorResponse = {
13+
code: number;
14+
message: string;
15+
more_info: string;
16+
};
17+
1418
export async function getFunctionServiceSid(
1519
cwd: string
1620
): Promise<string | undefined> {

0 commit comments

Comments
 (0)