Remove $FlowFixMe[sketchy-null-string] (errors.js) (#59976)

Summary:

Replace the optional original error stack's `||` fallback with an explicit null-or-empty ternary. Read the stack getter once in the Error branch and preserve the direct string branch, including `''`. Null/undefined/empty stacks still evaluate the existing `''.split('\n').slice(0, 2).join('\n')` fallback; nonempty stacks are unchanged. Do not alter the fallback's existing behavior.

Changelog: [Internal]

Differential Revision: D129900981

Pull Request resolved: https://github.com/react/react-native/pull/59976
This commit is contained in:
JC Perez Chavez authored and GitHub committed 2026-11-12 17:35:24 +00:00
1 parent aedc2e739a
commit de7e643aa3
1 file changed
+9 -5
@@ -16,11 +16,15 @@ export class CLIError extends Error {
constructor(msg: string, originalError?: Error | string) {
super(inlineString(msg));
if (originalError != null) {
this.stack =
typeof originalError === 'string'
? originalError
: // $FlowFixMe[sketchy-null-string]
originalError.stack || ''.split('\n').slice(0, 2).join('\n');
if (typeof originalError === 'string') {
this.stack = originalError;
} else {
const originalStack = originalError.stack;
this.stack =
originalStack == null || originalStack === ''
? ''.split('\n').slice(0, 2).join('\n')
: originalStack;
}
} else {
// When the "originalError" is not passed, it means that we know exactly
// what went wrong and provide means to fix it. In such cases showing the