Skip to content

Commit 11630dd

Browse files
committed
fix: require runtime evidence for crash diagnostics
1 parent ade9bfc commit 11630dd

10 files changed

Lines changed: 294 additions & 69 deletions

File tree

‎include/vix/cli/errors/RawLogDetectors.hpp‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,30 @@
1818

1919
namespace vix::cli::errors
2020
{
21+
/**
22+
* @brief Structured evidence captured from a completed runtime process.
23+
*
24+
* Text emitted by the application is not, by itself, evidence of a runtime
25+
* fault. Signal termination and recognized sanitizer diagnostics provide
26+
* the provenance required before runtime error rules may classify a run.
27+
*/
28+
struct RuntimeCrashEvidence final
29+
{
30+
bool terminatedBySignal{false};
31+
int termSignal{0};
32+
};
33+
2134
class RawLogDetectors
2235
{
2336
public:
37+
/**
38+
* @brief Returns whether a process result and its log establish a runtime event.
39+
*/
40+
[[nodiscard]]
41+
static bool hasAuthoritativeRuntimeEvidence(
42+
const std::string &runtimeLog,
43+
const RuntimeCrashEvidence &evidence);
44+
2445
static bool handleLinkerOrSanitizer(
2546
const std::string &buildLog,
2647
const std::filesystem::path &sourceFile,
@@ -29,7 +50,8 @@ namespace vix::cli::errors
2950
static bool handleRuntimeCrash(
3051
const std::string &runtimeLog,
3152
const std::filesystem::path &sourceFile,
32-
const std::string &contextMessage);
53+
const std::string &contextMessage,
54+
const RuntimeCrashEvidence &evidence = {});
3355

3456
static bool handleKnownRunFailure(const std::string &log, const std::filesystem::path &ctx);
3557
};

‎src/commands/RunCommand.cpp‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -738,15 +738,21 @@ namespace
738738
log += tr.stdoutText;
739739

740740
bool handled = false;
741+
const vix::cli::errors::RuntimeCrashEvidence evidence{
742+
tr.terminatedBySignal,
743+
tr.termSignal};
741744

742-
if (!log.empty())
745+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
746+
log,
747+
evidence))
743748
{
744749
const fs::path diagnosticPath{};
745750

746751
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
747752
log,
748753
diagnosticPath,
749-
"Test crashed");
754+
"Test crashed",
755+
evidence);
750756

751757
if (!handled &&
752758
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, diagnosticPath))
@@ -882,8 +888,13 @@ namespace
882888
log += rr.stdoutText;
883889

884890
bool handled = false;
891+
const vix::cli::errors::RuntimeCrashEvidence evidence{
892+
rr.terminatedBySignal,
893+
rr.termSignal};
885894

886-
if (!log.empty())
895+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
896+
log,
897+
evidence))
887898
{
888899
const fs::path diagnosticPath =
889900
opt.singleCpp
@@ -893,7 +904,8 @@ namespace
893904
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
894905
log,
895906
diagnosticPath,
896-
failureContext);
907+
failureContext,
908+
evidence);
897909

898910
if (!handled &&
899911
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, diagnosticPath))

‎src/commands/check/CheckProject.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,18 @@ namespace vix::commands::CheckCommand::detail
658658
}
659659

660660
bool handled = false;
661-
if (!runtimeLog.empty())
661+
const vix::cli::errors::RuntimeCrashEvidence evidence{
662+
rr.terminatedBySignal,
663+
rr.termSignal};
664+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
665+
runtimeLog,
666+
evidence))
662667
{
663668
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
664669
runtimeLog,
665670
projectDir,
666-
"Project check failed (runtime)");
671+
"Project check failed (runtime)",
672+
evidence);
667673

668674
if (!handled &&
669675
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(runtimeLog, projectDir))

‎src/commands/check/CheckScript.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,19 @@ namespace vix::commands::CheckCommand::detail
506506
}
507507

508508
bool handled = false;
509+
const vix::cli::errors::RuntimeCrashEvidence evidence{
510+
rr.terminatedBySignal,
511+
rr.termSignal};
509512

510-
if (!runtimeLog.empty())
513+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
514+
runtimeLog,
515+
evidence))
511516
{
512517
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
513518
runtimeLog,
514519
script,
515-
"Script check failed (runtime sanitizers)");
520+
"Script check failed (runtime sanitizers)",
521+
evidence);
516522

517523
if (!handled &&
518524
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(runtimeLog, script))

‎src/commands/run/RunScript.cpp‎

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -781,16 +781,6 @@ namespace vix::commands::RunCommand::detail
781781
#endif
782782

783783
#ifndef _WIN32
784-
bool log_looks_like_sanitizer_or_ub(const std::string &log)
785-
{
786-
return log.find("runtime error:") != std::string::npos ||
787-
log.find("UndefinedBehaviorSanitizer") != std::string::npos ||
788-
log.find("AddressSanitizer") != std::string::npos ||
789-
log.find("LeakSanitizer") != std::string::npos ||
790-
log.find("ThreadSanitizer") != std::string::npos ||
791-
log.find("MemorySanitizer") != std::string::npos;
792-
}
793-
794784
bool handle_error_tip_block_vix(const std::string &log)
795785
{
796786
const auto epos = log.find("error:");
@@ -852,27 +842,6 @@ namespace vix::commands::RunCommand::detail
852842
}
853843
#endif
854844

855-
#ifndef _WIN32
856-
bool log_looks_like_runtime_crash(const LiveRunResult &rr, const std::string &log)
857-
{
858-
if (rr.terminatedBySignal)
859-
return true;
860-
861-
if (log_looks_like_sanitizer_or_ub(log))
862-
return true;
863-
864-
return log.find("Segmentation fault") != std::string::npos ||
865-
log.find("segmentation fault") != std::string::npos ||
866-
log.find("core dumped") != std::string::npos ||
867-
log.find("Aborted") != std::string::npos ||
868-
log.find("terminate called") != std::string::npos ||
869-
log.find("std::terminate") != std::string::npos ||
870-
log.find("double free") != std::string::npos ||
871-
log.find("invalid pointer") != std::string::npos ||
872-
log.find("stack smashing detected") != std::string::npos;
873-
}
874-
#endif
875-
876845
bool has_ccache()
877846
{
878847
#ifdef _WIN32
@@ -1553,41 +1522,51 @@ namespace vix::commands::RunCommand::detail
15531522
{
15541523
return 0;
15551524
}
1556-
const bool looksSanOrUb =
1557-
!runtimeLog.empty() && log_looks_like_sanitizer_or_ub(runtimeLog);
1525+
const vix::cli::errors::RuntimeCrashEvidence evidence{
1526+
rr.terminatedBySignal,
1527+
rr.termSignal};
1528+
const bool hasRuntimeEvidence =
1529+
vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
1530+
runtimeLog,
1531+
evidence);
15581532

15591533
const bool noOutput =
15601534
trim_copy(rr.stdoutText).empty() &&
15611535
trim_copy(rr.stderrText).empty();
15621536

1563-
if (runCode == 0 && !looksSanOrUb && noOutput)
1537+
if (runCode == 0 && !hasRuntimeEvidence && noOutput)
15641538
{
15651539
if (!opt.quiet || ::isatty(STDOUT_FILENO) != 0)
15661540
vix::cli::style::hint("Program exited successfully (code 0) but produced no output.");
15671541

15681542
return 0;
15691543
}
15701544

1571-
if (runCode != 0 || looksSanOrUb)
1545+
if (runCode != 0 || hasRuntimeEvidence)
15721546
{
1573-
if (runCode == 0 && looksSanOrUb)
1547+
if (runCode == 0 && hasRuntimeEvidence)
15741548
runCode = 1;
15751549

15761550
bool handled = false;
15771551

15781552
if (!runtimeLog.empty())
15791553
{
1580-
handled = handle_error_tip_block_vix(runtimeLog);
1554+
if (hasRuntimeEvidence)
1555+
handled = handle_error_tip_block_vix(runtimeLog);
15811556

15821557
const bool maybeRuntimeCrash =
1583-
!handled && log_looks_like_runtime_crash(rr, runtimeLog);
1558+
!handled &&
1559+
vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
1560+
runtimeLog,
1561+
evidence);
15841562

15851563
if (maybeRuntimeCrash)
15861564
{
15871565
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
15881566
runtimeLog,
15891567
state.script,
1590-
"Script execution failed");
1568+
"Script execution failed",
1569+
evidence);
15911570

15921571
if (!handled &&
15931572
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(runtimeLog, state.script))
@@ -1642,13 +1621,19 @@ namespace vix::commands::RunCommand::detail
16421621
log += rr.stdoutText;
16431622

16441623
bool handled = false;
1624+
const vix::cli::errors::RuntimeCrashEvidence evidence{
1625+
rr.terminatedBySignal,
1626+
rr.termSignal};
16451627

1646-
if (!log.empty())
1628+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
1629+
log,
1630+
evidence))
16471631
{
16481632
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
16491633
log,
16501634
state.script,
1651-
"Script execution failed");
1635+
"Script execution failed",
1636+
evidence);
16521637

16531638
if (!handled &&
16541639
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(log, state.script))
@@ -2518,13 +2503,19 @@ namespace vix::commands::RunCommand::detail
25182503
if (exitCode != 0)
25192504
{
25202505
bool handled = false;
2506+
const vix::cli::errors::RuntimeCrashEvidence evidence{
2507+
WIFSIGNALED(status),
2508+
WIFSIGNALED(status) ? WTERMSIG(status) : 0};
25212509

2522-
if (!runtimeLog.empty())
2510+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
2511+
runtimeLog,
2512+
evidence))
25232513
{
25242514
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
25252515
runtimeLog,
25262516
script,
2527-
label + " exited with code " + std::to_string(exitCode));
2517+
label + " exited with code " + std::to_string(exitCode),
2518+
evidence);
25282519

25292520
if (!handled &&
25302521
vix::cli::errors::RawLogDetectors::handleKnownRunFailure(runtimeLog, script))

‎src/commands/run/detail/DirectScriptRunner.cpp‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,14 +1624,23 @@ namespace vix::commands::RunCommand::detail
16241624
{
16251625
std::string runtimeLog = run.stderrText;
16261626
runtimeLog += run.stdoutText;
1627+
const vix::cli::errors::RuntimeCrashEvidence evidence{
1628+
run.terminatedBySignal,
1629+
run.termSignal};
16271630

1628-
if (!runtimeLog.empty())
1631+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
1632+
runtimeLog,
1633+
evidence))
16291634
{
16301635
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
16311636
runtimeLog,
16321637
plan.scriptPath,
1633-
"run");
1638+
"run",
1639+
evidence);
16341640
}
1641+
1642+
if (!handled && !runtimeLog.empty() && !run.printed_live)
1643+
std::cerr << runtimeLog << "\n";
16351644
}
16361645

16371646
handle_runtime_exit_code(run.exitCode, "run", handled);

‎src/commands/run/dev/DevSession.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,13 +1005,19 @@ namespace vix::commands::RunCommand::dev
10051005
if (exitCode != 0)
10061006
{
10071007
bool handled = false;
1008+
const vix::cli::errors::RuntimeCrashEvidence evidence{
1009+
WIFSIGNALED(status),
1010+
WIFSIGNALED(status) ? WTERMSIG(status) : 0};
10081011

1009-
if (!runtimeLog.empty())
1012+
if (vix::cli::errors::RawLogDetectors::hasAuthoritativeRuntimeEvidence(
1013+
runtimeLog,
1014+
evidence))
10101015
{
10111016
handled = vix::cli::errors::RawLogDetectors::handleRuntimeCrash(
10121017
runtimeLog,
10131018
exePath,
1014-
"Dev server exited with code " + std::to_string(exitCode));
1019+
"Dev server exited with code " + std::to_string(exitCode),
1020+
evidence);
10151021
}
10161022

10171023
if (!handled)

0 commit comments

Comments
 (0)