exception_details 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -14,9 +14,9 @@ Features/benefits:
14
14
 
15
15
  * A single method for a loggable string (avoid repeating exception log string creation)
16
16
 
17
- * Get Pry like debug knowledge from cron job errors and running systems from the log, without being there.
17
+ * Log Pry-like debug info from cron errors and running systems without being there.
18
18
 
19
- * Pry type information with less overhead/dependencies--binding_of_caller is the only dependency.
19
+ * Debug information with less overhead/dependencies--binding_of_caller is the only dependency.
20
20
 
21
21
 
22
22
  ## Example Usage
@@ -30,7 +30,6 @@ Features/benefits:
30
30
  puts e.inspect_variables
31
31
  end
32
32
 
33
-
34
33
  e.details ->
35
34
 
36
35
  Exception:
@@ -56,6 +55,14 @@ Or access the variables in the binding yourself...
56
55
 
57
56
  e.binding_during_exception.eval("puts #{greeting}")
58
57
 
58
+ ## Filtering
59
+
60
+ If you need to hide certain variable values, such as passwords, private keys,
61
+ etc., you can configure an array of variable names to be filtered. Symbols
62
+ or strings may be used. The filter settings are global across all exceptions.
63
+
64
+ Exception.filter_variables = [:password, :username, :enjoys_php]
65
+
59
66
  ## Installation
60
67
 
61
68
  Add to your Gemfile:
@@ -71,7 +78,7 @@ Require it:
71
78
  require 'exception_details'
72
79
 
73
80
  ## Limitations
74
- - This gem requires [binding\_of\_caller]:https://github.com/banister/binding_of_caller, so it should only work with MRI 1.9.2, 1.9.3, 2.0
81
+ - This gem requires [binding\_of\_caller](https://github.com/banister/binding_of_caller), so it should only work with MRI 1.9.2, 1.9.3, 2.0
75
82
  and RBX (Rubinius). Does not work in 1.8.7, but there is a well known (continuation-based)
76
83
  hack to get a Binding#of_caller there. There is some mention about binding of caller supporting
77
84
  jruby, so feel free to try it out.
@@ -80,7 +87,7 @@ jruby, so feel free to try it out.
80
87
 
81
88
  - This gem is still new...
82
89
 
83
- - binding of caller is experiencing some segfault issues on some rubies, so this is not
90
+ - binding_of_caller is experiencing some segfault issues on some rubies, so this is not
84
91
  ideal for a production stack... Shame, as how awesome would using this in production be?
85
92
 
86
93
  ## Contributing
@@ -5,6 +5,26 @@ class Exception
5
5
  include ExceptionDetails::InspectVariables
6
6
  include ExceptionDetails::LogColorHelpers
7
7
 
8
+
9
+ @@filter_variables = []
10
+
11
+ # Configure an array of variable names to obscure during variable inspection.
12
+ # variables may be either symbols, or strings.
13
+ # This provides a way to make sure your logs don't have usernames,
14
+ # passwords, or private keys. Also, beware of hashes containing
15
+ # keys you want obscured.
16
+
17
+ # Filtered items will show up with variable values like '**FILTERED**'
18
+
19
+ def self.filter_variables=(variable_names_to_filter)
20
+ variable_names_to_filter = variable_names_to_filter.map {|v| v.to_s}
21
+ @@filter_variables = variable_names_to_filter
22
+ end
23
+
24
+ def self.filter_variables
25
+ @@filter_variables
26
+ end
27
+
8
28
  # binding_during_exception lets you actually directly access
9
29
  # the exception-time binding.
10
30
  attr_accessor :binding_during_exception
@@ -19,7 +19,11 @@ module ExceptionDetails
19
19
  variable_names = target_binding.eval(variable_scope.to_s)
20
20
  variable_names.each do |vname|
21
21
  value = target_binding.eval(vname.to_s)
22
- variable_value_string = "\t" + sprintf("%-35s = %s", "<#{value.class}> #{vname}", value.inspect)
22
+ if self.class.filter_variables.include?(vname.to_s)
23
+ value = '**FILTERED**'
24
+ end
25
+ variable_value_string = "\t" + sprintf("%-35s = %s", "<#{value.class}> #{vname}", value.inspect)
26
+
23
27
  unless value == self # don't list the exception itself ...
24
28
  variable_strings << variable_value_string
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module ExceptionDetails
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -106,4 +106,52 @@ describe "ExceptionDetails" do
106
106
 
107
107
  end
108
108
 
109
+ context "variable value filtering" do
110
+ before :each do
111
+ Exception.filter_variables = [:hideme]
112
+ end
113
+
114
+ it "should let you configure filter variables on the Exception class" do
115
+ Exception.respond_to?(:filter_variables).should be_true
116
+ StandardError.respond_to?(:filter_variables).should be_true
117
+ end
118
+
119
+ it "should convert filter_variable names to strings on assignment" do
120
+ Exception.filter_variables = [:foo]
121
+ Exception.filter_variables.should == ['foo']
122
+ end
123
+
124
+ it "should share all assigned filtering across all exception classes" do
125
+ Exception.filter_variables = [:hello]
126
+ (Exception.filter_variables == ['hello']).should be_true
127
+ (Exception.filter_variables == StandardError.filter_variables).should be_true
128
+ end
129
+
130
+ it "should filter selected variable values" do
131
+ hideme = 'shouldntseeme'
132
+ showme = 'shouldseeme'
133
+ begin
134
+ raise "hell"
135
+ rescue Exception => e
136
+ #variable name still shows up
137
+ e.inspect_variables.include?('hideme').should be_true
138
+
139
+ # but not the value
140
+ e.inspect_variables.include?('shouldntseeme').should be_false
141
+ e.inspect_variables.include?('**FILTERED**').should be_true
142
+ end
143
+ end
144
+
145
+ it "should not filter other variables" do
146
+ hideme = 'shouldntseeme'
147
+ showme = 'shouldseeme'
148
+ begin
149
+ raise "hell"
150
+ rescue Exception => e
151
+ e.inspect_variables.include?('shouldseeme').should be_true
152
+ end
153
+ end
154
+
155
+ end
156
+
109
157
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_details
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-15 00:00:00.000000000 Z
12
+ date: 2013-07-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler