From 1659a1660ce32c7ab926586a270c38ddfd0764e4 Mon Sep 17 00:00:00 2001 From: kazu Date: Fri, 2 Feb 2018 11:03:22 +0000 Subject: [PATCH] Use more verbose status in error messages of `system` with `exception: true` like `Process::Status#inspect` [Feature #14386] [ruby-core:85013] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- process.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/process.c b/process.c index 8b8268e9f1..6ad9216564 100644 --- a/process.c +++ b/process.c @@ -548,7 +548,8 @@ pst_pid(VALUE st) static void pst_message(VALUE str, rb_pid_t pid, int status) { - rb_str_catf(str, "pid %ld", (long)pid); + if (pid != (rb_pid_t)-1) + rb_str_catf(str, "pid %ld", (long)pid); if (WIFSTOPPED(status)) { int stopsig = WSTOPSIG(status); const char *signame = ruby_signal_name(stopsig); @@ -4090,8 +4091,10 @@ rb_f_system(int argc, VALUE *argv) status = PST2INT(rb_last_status_get()); if (status == EXIT_SUCCESS) return Qtrue; if (eargp->exception) { - rb_raise(rb_eRuntimeError, "Command failed with status (%d): %s", - WEXITSTATUS(status), RSTRING_PTR(eargp->invoke.sh.shell_script)); + VALUE str = rb_str_buf_new(0); + pst_message(str, (rb_pid_t)-1, status); + rb_raise(rb_eRuntimeError, "Command failed with%"PRIsVALUE": %s", + str, RSTRING_PTR(eargp->invoke.sh.shell_script)); } else { return Qfalse;