@samitouri / QOS-React / commits / fc7467ac0e

[dx] Update error messages for config parsing

ghstack-source-id: 693a3526a73f1fbd25f4e59416f8c65a0f8f1235 Pull Request resolved: https://github.com/facebook/react-forget/pull/2857

Joe Savona committed Apr 17, 2024 at 18:16 UTC fc7467ac0ed735aefbfdddc7889d9f1b7aefccf1
3 files changed +12 -9
compiler/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+2 -1
@@ -299,7 +299,8 @@ export function compileProgram(
299 */
300 if (environment.isErr()) {
301 CompilerError.throwInvalidConfig({
302 - reason: "Error in validating environment config",
302 + reason:
303 + "Error in validating environment config. This is an advanced setting and not meant to be used directly",
304 description: environment.unwrapErr().toString(),
305 suggestions: null,
306 loc: null,
compiler/packages/babel-plugin-react-forget/src/HIR/Environment.ts
+9 -7
@@ -393,9 +393,9 @@ export function parseConfigPragma(pragma: string): EnvironmentConfig {
393 if (config.success) {
394 return config.data;
395 }
396 - CompilerError.throwInvalidConfig({
397 - reason: `${fromZodError(config.error)}`,
398 - description: "Update Forget config to fix the error",
396 + CompilerError.invariant(false, {
397 + reason: "Internal error, could not parse config from pragma string",
398 + description: `${fromZodError(config.error)}`,
399 loc: null,
400 suggestions: null,
401 });
@@ -597,8 +597,9 @@ export function validateEnvironmentConfig(
597 }
598
599 CompilerError.throwInvalidConfig({
600 - reason: `${fromZodError(config.error)}`,
601 - description: "Update Forget config to fix the error",
600 + reason:
601 + "Could not validate environment config. Update React Compiler config to fix the error",
602 + description: `${fromZodError(config.error)}`,
603 loc: null,
604 suggestions: null,
605 });
@@ -615,8 +616,9 @@ export function tryParseExternalFunction(
616 }
617
618 CompilerError.throwInvalidConfig({
618 - reason: `${fromZodError(externalFunction.error)}`,
619 - description: "Update Forget config to fix the error",
619 + reason:
620 + "Could not parse external function. Update React Compiler config to fix the error",
621 + description: `${fromZodError(externalFunction.error)}`,
622 loc: null,
623 suggestions: null,
624 });
compiler/packages/babel-plugin-react-forget/src/__tests__/envConfig-test.ts
+1 -1
@@ -20,7 +20,7 @@ describe("parseConfigPragma()", () => {
20 validateHooksUsage: 1,
21 } as any);
22 }).toThrowErrorMatchingInlineSnapshot(
23 - `"InvalidConfig: Validation error: Expected boolean, received number at "validateHooksUsage". Update Forget config to fix the error"`
23 + `"InvalidConfig: Could not validate environment config. Update React Compiler config to fix the error. Validation error: Expected boolean, received number at "validateHooksUsage""`
24 );
25 });
26