• Stars
    star
    281
  • Rank 147,023 (Top 3 %)
  • Language
    Ruby
  • License
    Other
  • Created over 8 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Add custom processing for warnings

ruby-warningยถ โ†‘

ruby-warning adds custom processing for warnings, including the ability to ignore specific warning messages, ignore warnings in specific files/directories, include backtraces with warnings, treat warnings as errors, deduplicate warnings, and add custom handling for all warnings in specific files/directories.

ruby-warning requires ruby 2.4+, as previous versions of ruby do not support custom processing of warnings.

Installationยถ โ†‘

gem install warning

Source Codeยถ โ†‘

Source code is available on GitHub at github.com/jeremyevans/ruby-warning

Usage ยถ โ†‘

By default, requiring the library does not make changes to how ruby processes warnings, it just adds methods that allow you to customize the processing.

Warning.ignore takes a regexp and optionally a path prefix, and ignores any warning that matches the regular expression if it starts with the path prefix. It can also take a symbol or an array of symbols, and will use an appropriate regexp. The supported symbols are:

  • :arg_prefix

  • :ambiguous_slash

  • :bignum

  • :fixnum

  • :keyword_separation

  • :method_redefined

  • :mismatched_indentations

  • :missing_gvar

  • :missing_ivar

  • :not_reached

  • :safe

  • :shadow

  • :taint

  • :unused_var

  • :useless_operator

  • :void_context

Warning.process takes an optional path prefix and a block, and if the warning string starts with the path prefix, it calls the block with the warning string instead of performing the default behavior. You can call Warning.process multiple times and it will operate intelligently, choosing the longest path prefix that the string starts with.

Warning.process blocks can return :default to use the default behavior, :backtrace to use the default behavior and also print the backtrace or :raise to raise the warning string as a RuntimeError.

Warning.process can also accept a hash of actions instead of a block, with keys being regexps (or symbols supported by Warning.ignore) and values being callable objects (or :default, :backtrace, or :raise).

Warning.dedup deduplicates warnings, so that if a warning is received that is the same as a warning that has already been processed, the warning is ignored. Note that this should be used with care, since if the application generates an arbitrary number of unique warnings, that can lead to unbounded memory growth.

Warning.clear resets the library to its initial state, clearing the current ignored warnings and warning processors, and turning off deduplication.

By using path prefixes, itโ€™s fairly easy for a gem to set that specific warnings should be ignored inside the gemโ€™s directory.

Note that path prefixes will not correctly handle warnings raised by Kernel#warn, unless the warning message given to Kernel#warn starts with the filename where the warning is used. The Kernel#warn :uplevel option will make sure the warning starts with the filename.

Note that many of the warnings this library can ignore are warnings caused during compilation (i.e. when files are loaded via require). You should require this library and setup the appropriate warning handling before loading any code that could cause warnings.

Examplesยถ โ†‘

# Ignore all uninitialized instance variable warnings
Warning.ignore(/instance variable @\w+ not initialized/)

# Ignore all uninitialized instance variable warnings in current file
Warning.ignore(/instance variable @\w+ not initialized/, __FILE__)

# Ignore all uninitialized instance variable warnings in current file
Warning.ignore(:missing_ivar, __FILE__)

# Ignore all Fixnum and Bignum warnings in current file
Warning.ignore([:fixnum, :bignum], __FILE__)

# Write warning to LOGGER at level warning
Warning.process do |warning|
  LOGGER.warning(warning)
end

# Write warnings in the current file to LOGGER at level error
Warning.process(__FILE__) do |warning|
  LOGGER.error(warning)
end

# Write warnings in the current file to $stderr, but include backtrace
Warning.process(__FILE__) do |warning|
  :backtrace
end

# Raise warnings in the current file as RuntimeErrors, with the warning
# string as the exception message
Warning.process(__FILE__) do |warning|
  :raise
end

# Raise keyword argument separation warnings in the current file as
# RuntimeErrors, and write ambiguous slash warnings to $stderr, including
# the backtrace
Warning.process(__FILE__, keyword_separation: :raise,
                ambiguous_slash: :backtrace)

# Deduplicate warnings
Warning.dedup

# Ignore all warnings in Gem dependencies
Gem.path.each do |path|
  Warning.ignore(//, path)
end

Licenseยถ โ†‘

MIT

Authorยถ โ†‘

Jeremy Evans <[email protected]>

More Repositories

1

sequel

Sequel: The Database Toolkit for Ruby
Ruby
4,818
star
2

rodauth

Ruby's Most Advanced Authentication Framework
Ruby
1,550
star
3

home_run

Fast Date/DateTime classes for ruby :: Unmaintained, unnecessary on ruby 1.9.3+
Ruby
466
star
4

erubi

Small ERB Implementation
Ruby
373
star
5

forme

HTML forms library for ruby
Ruby
291
star
6

roda-sequel-stack

Application Skeleton For Roda/Sequel stack
Ruby
262
star
7

sequel_pg

Faster SELECTs when using Sequel with pg
C
258
star
8

ruby-refrigerator

Freeze all core ruby classes
Ruby
198
star
9

ruby-american_date

American style month/day/year parsing for ruby 1.9+
Ruby
108
star
10

by

Ruby Library Preloader
Ruby
101
star
11

sequel_postgresql_triggers

Database enforced timestamps, immutable columns, and counter/sum caches
Ruby
97
star
12

minitest-hooks

Around and before_all/after_all/around_all hooks for Minitest
Ruby
89
star
13

rack-unreloader

Rack Application that reloads application files if changed, unloading constants first
Ruby
88
star
14

autoforme

Web Administrative Console for Roda/Sinatra/Rails and Sequel::Model
Ruby
62
star
15

scaffolding_extensions

Ruby Web Admin Front-End :: Unmaintained, use AutoForme instead
Ruby
57
star
16

zozo

Simple $LOAD_PATH management for ruby projects :: Unmaintained
Ruby
49
star
17

aqualung

Advanced music player
C
48
star
18

fixture_dependencies

Sequel/ActiveRecord fixture loader that handles dependency graphs
Ruby
45
star
19

third_base

A Fast and Easy Date/DateTime Class for Ruby :: Unmaintained, use home_run instead.
Ruby
39
star
20

giftsmas

Gift Tracking Website using Roda and Sequel
Ruby
36
star
21

simple_orm_benchmark

A small benchmark test for ruby ORMs.
Ruby
31
star
22

spam

Simple Personal Accounting Manager
Ruby
30
star
23

tilt

Generic interface to multiple Ruby template engines
Ruby
30
star
24

simple_ldap_authenticator

Simple authentication for Ruby using LDAP
Ruby
29
star
25

roda-route_list

List routes when using Roda
Ruby
27
star
26

ruby-pledge

Ruby Interface to OpenBSD pledge(2) system call
Ruby
26
star
27

kaeruera

Simple Error Tracker for Ruby
Ruby
24
star
28

roda-rails

Integration for using Roda as Rack middleware in a Rails app
Ruby
21
star
29

thamble

Create HTML Tables from Enumerables
Ruby
18
star
30

exception_notification

Gemified exception_notification rails plugin, compatible with Rails 2.3.5 with the RailsXss plugin :: Unmaintained
Ruby
17
star
31

roda-message_bus

MessageBus integration for Roda
Ruby
17
star
32

evilr

Do things you shouldn't ::Unmaintained
Ruby
13
star
33

rack-indifferent

Fast indifferent access to request params
Ruby
13
star
34

ruby-subset_sum

Simple Subset Sum Solver with C and Pure Ruby Versions
Ruby
12
star
35

ruby-style

Supervised TCPServer, Yielding Listeners Easily :: Unmaintained, switch to Unicorn or Rainbows!
Ruby
12
star
36

ape_tag_libs

Libaries for reading/writing APEv2 tags in many languages
C
11
star
37

gcit2ghi

Imports issues from Google Code Issue Tracker to GitHub Issues :: Unmaintained
Ruby
11
star
38

rack-deadline

Automatically clears sessions open too long
Ruby
11
star
39

minitest-parallel_fork

Fork-based parallelization for minitest
Ruby
11
star
40

ruby-deprecate_public

Warn when calling private methods via public interface
Ruby
11
star
41

cspvr

Content-Security-Policy Violation Recorder
Ruby
10
star
42

unicorn-lockdown

Helper library for running Unicorn on OpenBSD with chroot, privdrop, fork+exec, and pledge
Ruby
9
star
43

visibility_checker

Detect method visibility changes
Ruby
9
star
44

minitest-shared_description

Support for shared specs and shared spec subclasses for Minitest
Ruby
8
star
45

jpm

Password manager using openssl/signify
Ruby
8
star
46

sequel-mongo

Proof of Concept MongoDB Driver for Sequel (Do not use in production)
Ruby
7
star
47

quinto

Quinto server and client
Ruby
7
star
48

capybara-validate_html5

Validate HTML5 for each page accessed when testing with capybara
Ruby
7
star
49

minitest-global_expectations

Support minitest expectation methods for all objects
Ruby
6
star
50

simple_mailer

Simple email library with testing support
Ruby
6
star
51

roda-opal-example

Example of Using Roda with Opal
Ruby
6
star
52

rodauth-demo-rails

Rodauth's demo site ported to Rails, showing Rodauth/Rails integration
Ruby
5
star
53

enum_csv

Create CSV from Enumerables
Ruby
5
star
54

tilt-pipeline

Easily construct rendering pipelines using tilt
Ruby
5
star
55

lila_shell

Simple chat app using roda-message_bus
JavaScript
5
star
56

ruby-scgi

Simple support for using SCGI in ruby apps, such as Rails :: Unmaintained
Ruby
5
star
57

ruby-string-crypt

Backward compatible implementation of String#crypt
C
4
star
58

gg2ghd

Import Extract from Google Groups into GitHub Discussions
Ruby
4
star
59

tagged-ruby-bugs

Tagged Open Ruby Bugs
Ruby
3
star
60

openbsd-ruby-ports

Ports for Ruby Versions Removed from OpenBSD ports tree
Makefile
3
star
61

ruby-vorbis_comment

Ruby library for reading/writing vorbis comments
C
3
star
62

erubis

Git repository for http://www.kuwata-lab.com/erubis/
HTML
3
star
63

hs-SubsetSum

Subset sum problem solver for haskell
Haskell
3
star
64

tilt-rails_erb

Adds support for Rails' ERB templates to Tilt
Ruby
2
star
65

slab

Tutorial for building an OCR web application
Ruby
2
star
66

jeremyevans.github.com

Personal Website
HTML
2
star
67

sacruby

Various code related to the Sacramento Ruby Meetup
Ruby
2
star
68

sequel_validation_helpers_block

Allows easy determination of which validation rules apply to a given column, at the expense of increased verbosity
Ruby
2
star
69

sequel-impala

Support for Sequel to access the Impala database
1
star
70

mp3applygain

Apply gain information to mp3 audio data
C
1
star
71

openbsd-postgresql-ports

Ports for old PostgreSQL versions removed from the OpenBSD ports tree
Shell
1
star
72

faster_html_escape

Archive of old faster_html_escape gem
C
1
star
73

sequel-unsplit

Ruby code rewriter that replaces symbols containing embedded qualification/aliasing with equivalent Sequel code
Ruby
1
star
74

aqualung-scrobbler

last.fm scrobbler for Aqualung
Shell
1
star
75

rubyconflt2016-presentation

Presentation Source Code for my RubyConfLT 2016 presentation on Rodauth (runs on my showoff fork)
CSS
1
star
76

tilt-indirect

Adds indirection for tilt templates
Ruby
1
star
77

jeremyevans_github_hook_processor

Processor for GitHub webhooks for my repositories
Ruby
1
star
78

falcomcdcatalog

Falcom CD Catalog - English Edition
HTML
1
star
79

serverside

Ruby web framework from which Sequel was extracted
Ruby
1
star
80

tame_libs

programming language wrappers for OpenBSD's tame(2) system call
Ruby
1
star
81

capybara-restore_state

Restore capybara state after block execution
Ruby
1
star
82

openbsd-mariadb-ports

Ports for newer versions of MariaDB for OpenBSD
Makefile
1
star