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>'
Actions
Like0
Like0