Project

General

Profile

Feature #13246

[REQUEST] Allow to make rb_compile_warn a hard error

Added by kirs (Kir Shatrov) about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:79725]

Description

$ cat dup.rb
puts({ one: 1, one: 2})

$ ruby dup.rb
dup.rb:1: warning: key :one is duplicated and overwritten on line 1
{:one=>2}

I suppose it was initially made a warning for the backward compatibility reasons.

In case of our project, we'd like to raise on all warnings like this one and stop allowing developers to introduce the code with warnings.
This is a common error that developers make, especially when they use TDD and the test output is quite large and it's not easy to notice the warning.

I propose that we provide an API to catch rb_compile_warn events and allow to raise on them, or for instance report them to the exception notification library if it's running in production.

History

Updated by jeremyevans0 (Jeremy Evans) about 2 years ago

  • Status changed from Open to Closed

Ruby starting in 2.4 offers such an API:

def Warning.warn(str); raise str; end

This handles all internal warnings (raised by the interpreter itself) in 2.4. However, note that this will not handle warnings raised by Kernel#warn in 2.4, but it should starting in 2.5.

Also available in: Atom PDF