Skip to content

Commit 7dc8449

Browse files
rubennortefacebook-github-bot
authored andcommitted
Fix reporting of errors without stack traces (#52601)
Summary: Pull Request resolved: #52601 Changelog: [internal] Fixes a bug in Fantom when throwing a value that's not an instance of `Error` in a test. Reviewed By: javache Differential Revision: D78332756 fbshipit-source-id: 350479dcb7bcea399070c6851aca76a1d1cc2629
1 parent 2a93767 commit 7dc8449

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

private/react-native-fantom/runner/runner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ function buildError(
5959
sourceMapPath: string,
6060
): Error {
6161
const error = new Error(failureDetail.message);
62-
error.stack = symbolicateStackTrace(sourceMapPath, failureDetail.stack);
62+
if (failureDetail.stack != null) {
63+
error.stack = symbolicateStackTrace(sourceMapPath, failureDetail.stack);
64+
}
6365
if (failureDetail.cause != null) {
6466
error.cause = buildError(failureDetail.cause, sourceMapPath);
6567
}

private/react-native-fantom/runtime/setup.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type TestCaseResult = {
3030

3131
export type FailureDetail = {
3232
message: string,
33-
stack: string,
33+
stack?: string,
3434
cause?: FailureDetail,
3535
};
3636

@@ -320,7 +320,7 @@ function runSpec(spec: Spec): TestCaseResult {
320320
}
321321

322322
let status: 'passed' | 'failed' | 'pending';
323-
let error;
323+
let error: mixed;
324324

325325
const start = Date.now();
326326
snapshotContext.setTargetTest(result.fullName);
@@ -331,16 +331,21 @@ function runSpec(spec: Spec): TestCaseResult {
331331
invokeHooks(spec.parentContext, 'afterEachHooks');
332332

333333
status = 'passed';
334-
} catch (e) {
334+
} catch (e: mixed) {
335335
error = e;
336336
status = 'failed';
337337
}
338338

339339
result.status = status;
340340
result.duration = Date.now() - start;
341-
if (status === 'failed' && error) {
342-
result.failureMessages = [error.stack ?? error.message ?? String(error)];
343-
result.failureDetails = [serializeError(error)];
341+
if (status === 'failed' && error != null) {
342+
if (error instanceof Error) {
343+
result.failureMessages = [error.stack ?? error.message ?? String(error)];
344+
result.failureDetails = [serializeError(error)];
345+
} else {
346+
result.failureMessages = [`Non-error value thrown: ${String(error)}`];
347+
result.failureDetails = [];
348+
}
344349
} else {
345350
result.failureMessages = [];
346351
result.failureDetails = [];

0 commit comments

Comments
 (0)