[ruby-core:113189] [Ruby master Feature#19590] Include the invalid argument in error messages from `Process.clock_gettime` and `Process.clock_getres`
From:
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
Date:
2023-04-11 10:19:23 UTC
List:
ruby-core #113189
Issue #19590 has been reported by nobu (Nobuyoshi Nakada).
----------------------------------------
Feature #19590: Include the invalid argument in error messages from `Process.clock_gettime` and `Process.clock_getres`
https://bugs.ruby-lang.org/issues/19590
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
* Priority: Normal
----------------------------------------
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.
```shell-session
$ ./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.
```shell-session
$ ./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>'
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- [email protected]
To unsubscribe send an email to [email protected]
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/