Actions
Feature #19590
closedInclude the invalid argument in error messages from `Process.clock_gettime` and `Process.clock_getres`
Status:
Closed
Assignee:
-
Target version:
-
Description
The argument of Process.clock_gettime
and Process.clock_getres
is complex a little, it supports Integer
and Symbol
which are platform dependent.
In most cases, available clocks are defined as constants under Process
, but on some platforms (MinGW at least) some constants are defined but fails with EINVAL
, and the exception doesn't tell what was wrong.
$ ./ruby --disable=gems -v -e 'Process.constants.grep(/\ACLOCK_/).each {|c| clk = Process.const_get(c); p [c, clk, (Process.clock_gettime(clk) rescue $!)]}'
ruby 3.3.0dev (2023-02-23T18:13:13Z master 1fdaa06660) [x64-mingw-ucrt]
[:CLOCK_REALTIME_COARSE, 4, #<Errno::EINVAL: Invalid argument - clock_gettime>]
[:CLOCK_REALTIME, 0, 1681206710.103821]
[:CLOCK_MONOTONIC, 1, 167731.5111065]
[:CLOCK_PROCESS_CPUTIME_ID, 2, #<Errno::EINVAL: Invalid argument - clock_gettime>]
[:CLOCK_THREAD_CPUTIME_ID, 3, #<Errno::EINVAL: Invalid argument - clock_gettime>]
And it wastes time when passing a Symbol
with typo.
So my proposal is to add the argument to the exception message.
$ ./miniruby -e 'p Process.clock_gettime(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME)'
-e:1:in `clock_gettime': Invalid argument - clock_gettime(:CLOCK_BASED_CLOCK_PROCESS_CPUTIME) (Errno::EINVAL)
from -e:1:in `<main>'
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
- Status changed from Open to Closed
Applied in changeset git|3612b1bed8b4a93fd85d4be448174d5c6ef4f473.
[Feature #19590] Show the invalid clock argument
Include the failed clock argument in the error message from
Process.clock_gettime
and Process.clock_getres
.
Actions
Like0
Like0