Does ruby allow you to treat warnings as errors?
One reason I’d like to do this is to ensure that if heckle removing a line of code means that a warning occurs, I have the option of ensuring that the mutant get killed.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is unfortunately no real way of doing this, at least not on most versions of Ruby out there (variations may exist), short of monitoring the program output and aborting it when a warning appears on standard error. Here’s why:
Kernel.warn, which you can redefine to do whatever you wish (including exiting), and which you’d expect (hope) to be used consistently by Ruby to report warnings (including internal e.g. parsing warning), butrb_warnfromsource/server.c, completely bypassing your redefinition ofKernel.warn(e.g. the ‘string literal in condition‘ warning, for example, issued when doing something like:do_something if 'string', is printed via the nativerb_warnfromsource/parse.c)rb_warningnative method, which can be used by Ruby to log warnings if-wor-vis specified.So, if you need to take action solely on warnings generated by your application code’s calling
Kernel.warnthen simply redefineKernel.warn. Otherwise, you have exactly two options:source/error.cto exit inrb_warnandrb_warning(andrb_warn_m?), and rebuild Ruby: warning:‘, and abort it on match