Skip to content

Commit 0051335

Browse files
committed
Format issues and workarounds as a table.
1 parent 681121b commit 0051335

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/dataconnect/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export async function build(
3939
utils.logLabeledWarning(
4040
"dataconnect",
4141
`There are changes in your schema or connectors that may break your existing applications. These changes require explicit acknowledgement to proceed. You may either reject the changes and update your sources with the suggested workaround(s), if any, or acknowledge these changes and proceed with the deployment:\n` +
42-
requiredAcks.map(prettifyWithWorkaround).join("\n"),
42+
prettifyWithWorkaround(requiredAcks),
4343
);
4444
if (options.nonInteractive && !options.force) {
4545
throw new FirebaseError(

src/dataconnect/graphqlError.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as clc from "colorette";
21
import { GraphqlError } from "./types";
2+
const Table = require("cli-table");
33

44
export function prettify(err: GraphqlError): string {
55
const message = err.message;
@@ -13,13 +13,24 @@ export function prettify(err: GraphqlError): string {
1313
return header.length ? `${header}: ${message}` : message;
1414
}
1515

16-
export function prettifyWithWorkaround(err: GraphqlError): string {
17-
if (!err.extensions?.workarounds?.length) {
18-
return prettify(err);
19-
}
20-
let prettified = `\n${clc.bold("Issue:")} ${prettify(err)}`;
21-
for (const w of err.extensions.workarounds) {
22-
prettified += `\n${clc.bold("Workaround:")} ${w.Description}\n${clc.bold("Reason:")} ${w.Reason}`;
16+
export function prettifyWithWorkaround(errs: GraphqlError[]): string {
17+
const table = new Table({
18+
head: ["Issue", "Workaround", "Reason"],
19+
style: { head: ["yellow"] },
20+
});
21+
for (const e of errs) {
22+
if (!e.extensions?.workarounds?.length) {
23+
table.push([prettify(e), "", ""]);
24+
} else {
25+
const workarounds = e.extensions.workarounds;
26+
for (let i = 0; i < workarounds.length; i++) {
27+
if (i === 0) {
28+
table.push([prettify(e), workarounds[i].Description, workarounds[i].Reason]);
29+
} else {
30+
table.push(["", workarounds[i].Description, workarounds[i].Reason]);
31+
}
32+
}
33+
}
2334
}
24-
return prettified;
35+
return table.toString();
2536
}

0 commit comments

Comments
 (0)