From 0b434790d3dfd44668f5b6aad22979ee9e5dee52 Mon Sep 17 00:00:00 2001 From: giftkugel Date: Wed, 12 Sep 2018 15:12:08 -0700 Subject: [PATCH] Bad command-line for debugDiagnosticSeverity does not crashes Prepack anymore (#2545) Summary: This can be a possible fix for https://github.com/facebook/prepack/issues/2509 I have removed the `invariant` method call and added a value check as used for the _invariantMode_ option. `node lib/prepack-cli.js --debugDiagnosticSeverity foo` will now generate `Unsupported debugDiagnosticSeverity: foo` Pull Request resolved: https://github.com/facebook/prepack/pull/2545 Differential Revision: D9800485 Pulled By: hermanventer fbshipit-source-id: edc24b4a812b4e32f9c48e05a0799bf4af431991 --- src/options.js | 1 + src/prepack-cli.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/options.js b/src/options.js index 311ab7c379..02c4169937 100644 --- a/src/options.js +++ b/src/options.js @@ -33,6 +33,7 @@ export const InvariantModeValues = [ "nativeLoggingHook+2", "nativeLoggingHook+3", ]; +export const DiagnosticSeverityValues = ["FatalError", "RecoverableError", "Warning", "Information"]; export type ReactOutputTypes = "create-element" | "jsx" | "bytecode"; export const ReactOutputValues = ["create-element", "jsx", "bytecode"]; diff --git a/src/prepack-cli.js b/src/prepack-cli.js index b311cdc740..fd0903f372 100644 --- a/src/prepack-cli.js +++ b/src/prepack-cli.js @@ -19,6 +19,7 @@ import { ReactOutputValues, type InvariantModeTypes, InvariantModeValues, + DiagnosticSeverityValues, } from "./options.js"; import { type SerializedResult } from "./serializer/types.js"; import { TextPrinter } from "./utils/TextPrinter.js"; @@ -299,6 +300,10 @@ function run( break; case "debugDiagnosticSeverity": arg = args.shift(); + if (!DiagnosticSeverityValues.includes(arg)) { + console.error(`Unsupported debugDiagnosticSeverity: ${arg}`); + process.exit(1); + } invariant( arg === "FatalError" || arg === "RecoverableError" || arg === "Warning" || arg === "Information", `Invalid debugger diagnostic severity: ${arg}`