summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2024-11-07 09:35:19 -0500
committerGitHub <[email protected]>2024-11-07 09:35:19 -0500
commitfca07d73e3778a782fd719ceda606a62f028d1dc (patch)
tree1be6d8c8181676fbc45a899cdb745de0996c12d3 /error.c
parent3f7c72cd33566eb11497c1d41c2b94c98c364882 (diff)
Respect RUBY_CRASH_REPORT path when RUBY_ASSERT() fails
Previously, it always used stderr. Slight shuffle of the first line of the crash due to reusing code from rb_bug(): ```diff -Assertion Failed: /ruby/object.c:649:rb_obj_itself:false +/ruby/object.c:649: Assertion Failed: rb_obj_itself:false ``` Tested locally to confirm that it writes to the file given with RUBY_CRASH_REPORT. Follow-up for [Feature #19790].
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12019 Merged-By: XrXr
Diffstat (limited to 'error.c')
-rw-r--r--error.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/error.c b/error.c
index 05c89fe8e8..3fc1d96d6c 100644
--- a/error.c
+++ b/error.c
@@ -1173,23 +1173,27 @@ void
rb_assert_failure_detail(const char *file, int line, const char *name, const char *expr,
const char *fmt, ...)
{
- FILE *out = stderr;
- fprintf(out, "Assertion Failed: %s:%d:", file, line);
- if (name) fprintf(out, "%s:", name);
- fputs(expr, out);
+ rb_pid_t pid = -1;
+ FILE *out = bug_report_file(file, line, &pid);
+ if (out) {
+ fputs("Assertion Failed: ", out);
+ if (name) fprintf(out, "%s:", name);
+ fputs(expr, out);
+
+ if (fmt && *fmt) {
+ va_list args;
+ va_start(args, fmt);
+ fputs(": ", out);
+ vfprintf(out, fmt, args);
+ va_end(args);
+ }
+ fprintf(out, "\n%s\n\n", rb_dynamic_description);
- if (fmt && *fmt) {
- va_list args;
- va_start(args, fmt);
- fputs(": ", out);
- vfprintf(out, fmt, args);
- va_end(args);
+ preface_dump(out);
+ rb_vm_bugreport(NULL, out);
+ bug_report_end(out, pid);
}
- fprintf(out, "\n%s\n\n", rb_dynamic_description);
- preface_dump(out);
- rb_vm_bugreport(NULL, out);
- bug_report_end(out, -1);
die();
}