Skip to content

Commit

Permalink
Format issues and workarounds as a table.
Browse files Browse the repository at this point in the history
  • Loading branch information
rosalyntan committed Dec 18, 2024
1 parent 681121b commit 0051335
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/dataconnect/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function build(
utils.logLabeledWarning(
"dataconnect",
`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` +
requiredAcks.map(prettifyWithWorkaround).join("\n"),
prettifyWithWorkaround(requiredAcks),
);
if (options.nonInteractive && !options.force) {
throw new FirebaseError(
Expand Down
29 changes: 20 additions & 9 deletions src/dataconnect/graphqlError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as clc from "colorette";
import { GraphqlError } from "./types";
const Table = require("cli-table");

Check warning on line 2 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 2 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Require statement not part of import statement

export function prettify(err: GraphqlError): string {

Check warning on line 4 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const message = err.message;
Expand All @@ -13,13 +13,24 @@ export function prettify(err: GraphqlError): string {
return header.length ? `${header}: ${message}` : message;
}

export function prettifyWithWorkaround(err: GraphqlError): string {
if (!err.extensions?.workarounds?.length) {
return prettify(err);
}
let prettified = `\n${clc.bold("Issue:")} ${prettify(err)}`;
for (const w of err.extensions.workarounds) {
prettified += `\n${clc.bold("Workaround:")} ${w.Description}\n${clc.bold("Reason:")} ${w.Reason}`;
export function prettifyWithWorkaround(errs: GraphqlError[]): string {

Check warning on line 16 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Missing JSDoc comment
const table = new Table({

Check warning on line 17 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value

Check warning on line 17 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe construction of an any type value
head: ["Issue", "Workaround", "Reason"],
style: { head: ["yellow"] },
});
for (const e of errs) {
if (!e.extensions?.workarounds?.length) {
table.push([prettify(e), "", ""]);

Check warning on line 23 in src/dataconnect/graphqlError.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .push on an `any` value
} else {
const workarounds = e.extensions.workarounds;
for (let i = 0; i < workarounds.length; i++) {
if (i === 0) {
table.push([prettify(e), workarounds[i].Description, workarounds[i].Reason]);
} else {
table.push(["", workarounds[i].Description, workarounds[i].Reason]);
}
}
}
}
return prettified;
return table.toString();
}

0 comments on commit 0051335

Please sign in to comment.