[ruby-core:125889] [Ruby Feature#22136] `sprintf` shouldn't raise ArgumentError when $DEBUG is set
Issue #22136 has been reported by byroot (Jean Boussier). ---------------------------------------- Feature #22136: `sprintf` shouldn't raise ArgumentError when $DEBUG is set https://bugs.ruby-lang.org/issues/22136 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- ### Expected behavior If I'm tracking down a problem and suspect an error might be swallowed somewhere, I do run my test case with `RUBYOPT="-d"` (or simply set `$DEBUG = true`. I do expect the program to execute all in the same way than without `-d`, expect for extra output on STDERR. ### Actual behavior If some code happens to call `sprintf` or `String#%` with too many arguments, then it will raise an error and likely break the program, preventing me from simply running the same code but in debug mode. ### Reproduction ``` $ ruby -e 'sprintf("foo", "bar"); p :ok' :ok $ ruby -We 'sprintf("foo", "bar"); p :ok' -e:1: warning: too many arguments for format string :ok $ ruby -dWe 'sprintf("foo", "bar"); p :ok' Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1423 - cannot load such file -- rubygems/defaults/operating_system Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1438 - cannot load such file -- rubygems/defaults/ruby Exception 'ArgumentError' at -e:1 - too many arguments for format string Exception 'RuntimeError' at <internal:ast>:96 - cannot get AST for ISEQ compiled by prism -e:1:in 'Kernel#sprintf': too many arguments for format string (ArgumentError) from -e:1:in '<main>' ``` ### Bug or Feature? I looked around the Ruby codebase, as far as I can tell this is the only method behaving this way (aside from its aliases like `String#%`). So I filed this as a Feature, but really in my opinion it is a bug. -- https://bugs.ruby-lang.org/
Issue #22136 has been updated by ufuk (Ufuk Kayserilioglu). Could this be related to https://bugs.ruby-lang.org/issues/22129 ---------------------------------------- Feature #22136: `sprintf` shouldn't raise ArgumentError when $DEBUG is set https://bugs.ruby-lang.org/issues/22136#change-117835 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- ### Expected behavior If I'm tracking down a problem and suspect an error might be swallowed somewhere, I do run my test case with `RUBYOPT="-d"` (or simply set `$DEBUG = true`. I do expect the program to execute all in the same way than without `-d`, expect for extra output on STDERR. ### Actual behavior If some code happens to call `sprintf` or `String#%` with too many arguments, then it will raise an error and likely break the program, preventing me from simply running the same code but in debug mode. ### Reproduction ``` $ ruby -e 'sprintf("foo", "bar"); p :ok' :ok $ ruby -We 'sprintf("foo", "bar"); p :ok' -e:1: warning: too many arguments for format string :ok $ ruby -dWe 'sprintf("foo", "bar"); p :ok' Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1423 - cannot load such file -- rubygems/defaults/operating_system Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1438 - cannot load such file -- rubygems/defaults/ruby Exception 'ArgumentError' at -e:1 - too many arguments for format string Exception 'RuntimeError' at <internal:ast>:96 - cannot get AST for ISEQ compiled by prism -e:1:in 'Kernel#sprintf': too many arguments for format string (ArgumentError) from -e:1:in '<main>' ``` ### Bug or Feature? I looked around the Ruby codebase, as far as I can tell this is the only method behaving this way (aside from its aliases like `String#%`). So I filed this as a Feature, but really in my opinion it is a bug. Pull Request: https://github.com/ruby/ruby/pull/17579 -- https://bugs.ruby-lang.org/
Issue #22136 has been updated by byroot (Jean Boussier). I don't think so, the code very explicitly raises in debug mode: ```c if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg); ``` And that has been the case for at least 18 years: https://github.com/byroot/ruby/commit/549c345cefe03ab3f35b9cca1192a0062f288e..., and speced for about as long: https://github.com/ruby/spec/blame/06fba2498a086886191d05b91f57f1e54bf47e8f/... ---------------------------------------- Feature #22136: `sprintf` shouldn't raise ArgumentError when $DEBUG is set https://bugs.ruby-lang.org/issues/22136#change-117836 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- ### Expected behavior If I'm tracking down a problem and suspect an error might be swallowed somewhere, I do run my test case with `RUBYOPT="-d"` (or simply set `$DEBUG = true`. I do expect the program to execute all in the same way than without `-d`, expect for extra output on STDERR. ### Actual behavior If some code happens to call `sprintf` or `String#%` with too many arguments, then it will raise an error and likely break the program, preventing me from simply running the same code but in debug mode. ### Reproduction ``` $ ruby -e 'sprintf("foo", "bar"); p :ok' :ok $ ruby -We 'sprintf("foo", "bar"); p :ok' -e:1: warning: too many arguments for format string :ok $ ruby -dWe 'sprintf("foo", "bar"); p :ok' Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1423 - cannot load such file -- rubygems/defaults/operating_system Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1438 - cannot load such file -- rubygems/defaults/ruby Exception 'ArgumentError' at -e:1 - too many arguments for format string Exception 'RuntimeError' at <internal:ast>:96 - cannot get AST for ISEQ compiled by prism -e:1:in 'Kernel#sprintf': too many arguments for format string (ArgumentError) from -e:1:in '<main>' ``` ### Bug or Feature? I looked around the Ruby codebase, as far as I can tell this is the only method behaving this way (aside from its aliases like `String#%`). So I filed this as a Feature, but really in my opinion it is a bug. Pull Request: https://github.com/ruby/ruby/pull/17579 -- https://bugs.ruby-lang.org/
Issue #22136 has been updated by matz (Yukihiro Matsumoto). Accepted. The `$DEBUG` flag is meant to add diagnostic output, not to change program behavior. Raising `ArgumentError` for extra arguments only under `-d` violates that expectation and can prevent the very debugging session it was supposed to help. A warning on `$stderr` is enough. Matz. ---------------------------------------- Feature #22136: `sprintf` shouldn't raise ArgumentError when $DEBUG is set https://bugs.ruby-lang.org/issues/22136#change-118002 * Author: byroot (Jean Boussier) * Status: Open ---------------------------------------- ### Expected behavior If I'm tracking down a problem and suspect an error might be swallowed somewhere, I do run my test case with `RUBYOPT="-d"` (or simply set `$DEBUG = true`. I do expect the program to execute all in the same way than without `-d`, expect for extra output on STDERR. ### Actual behavior If some code happens to call `sprintf` or `String#%` with too many arguments, then it will raise an error and likely break the program, preventing me from simply running the same code but in debug mode. ### Reproduction ``` $ ruby -e 'sprintf("foo", "bar"); p :ok' :ok $ ruby -We 'sprintf("foo", "bar"); p :ok' -e:1: warning: too many arguments for format string :ok $ ruby -dWe 'sprintf("foo", "bar"); p :ok' Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1423 - cannot load such file -- rubygems/defaults/operating_system Exception 'LoadError' at .../lib/ruby/4.0.0/rubygems.rb:1438 - cannot load such file -- rubygems/defaults/ruby Exception 'ArgumentError' at -e:1 - too many arguments for format string Exception 'RuntimeError' at <internal:ast>:96 - cannot get AST for ISEQ compiled by prism -e:1:in 'Kernel#sprintf': too many arguments for format string (ArgumentError) from -e:1:in '<main>' ``` ### Bug or Feature? I looked around the Ruby codebase, as far as I can tell this is the only method behaving this way (aside from its aliases like `String#%`). So I filed this as a Feature, but really in my opinion it is a bug. Pull Request: https://github.com/ruby/ruby/pull/17579 -- https://bugs.ruby-lang.org/
participants (3)
-
byroot (Jean Boussier) -
matz (Yukihiro Matsumoto) -
ufuk (Ufuk Kayserilioglu)