Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
handle exceptions nicely
Browse files Browse the repository at this point in the history
  • Loading branch information
rsanheim committed Oct 31, 2008
1 parent ff5957b commit 2740cf3
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
v0.1.1. Handle exceptions from within the block

v0.1.0. Specify, clean up

v0.0.6. changed to mixing to Object by default - set ENV["SAFE_LOG_BUDDY"] = true to override
Expand Down
16 changes: 10 additions & 6 deletions lib/log_buddy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def bark
=end
class LogBuddy
VERSION = '0.1.0'
VERSION = '0.1.1'

# Use LogBuddy!
def self.init(options = {})
Expand Down Expand Up @@ -46,11 +46,15 @@ module Mixin
def d(msg = nil, &blk)
LogBuddy.debug(msg) if msg
return unless block_given?
logged_line = LogBuddy.read_line(caller[0])
arguments = LogBuddy.parse_args(logged_line)
arguments.each do |arg|
result = eval(arg, blk.binding)
LogBuddy.debug(%[#{arg} = '#{result}'\n])
begin
logged_line = LogBuddy.read_line(caller[0])
arguments = LogBuddy.parse_args(logged_line)
arguments.each do |arg|
result = eval(arg, blk.binding)
LogBuddy.debug(%[#{arg} = '#{result}'\n])
end
rescue Exception => e
LogBuddy.debug "LogBuddy caught an exception: #{e.message}"
end
end

Expand Down
10 changes: 6 additions & 4 deletions log_buddy.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{log_buddy}
s.version = "0.1.0"
s.version = "0.1.1"

s.required_rubygems_version = Gem::Requirement.new("= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Rob Sanheim - Relevance"]
s.date = %q{2008-09-29}
s.date = %q{2008-10-30}
s.description = %q{Log statements along with their name easily. Mixin a logger everywhere when you need it.}
s.email = %q{opensource@thinkrelevance.com}
s.extra_rdoc_files = ["CHANGELOG", "lib/log_buddy.rb", "LICENSE", "README.rdoc"]
Expand All @@ -14,14 +16,14 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Log_buddy", "--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{thinkrelevance}
s.rubygems_version = %q{1.2.0}
s.rubygems_version = %q{1.3.0}
s.summary = %q{Log Buddy is your little development buddy.}

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 2

if current_version >= 3 then
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<echoe>, [">= 0"])
s.add_development_dependency(%q<allison>, [">= 0"])
s.add_development_dependency(%q<markaby>, [">= 0"])
Expand Down
2 changes: 1 addition & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "test/spec"
require "test/spec/should-output"
require "mocha"
require "redgreen" rescue nil
require "redgreen" unless Object.const_defined?("TextMate")
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "log_buddy"))

def silence_warnings
Expand Down
9 changes: 9 additions & 0 deletions spec/log_buddy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def self.say_something(name)
def self.message
"hello"
end

def self.raise_exception
raise Exception
end
end

describe "LogBuddy" do
Expand Down Expand Up @@ -109,5 +113,10 @@ def self.message
LogBuddy.expects(:debug).with(%[@ivar1 = '1'\n])
d { local1; local2; @ivar1 }
end

it "should gracefully handle exceptions" do
LogBuddy.expects(:debug).with('LogBuddy caught an exception: Exception')
d { SomeModule.raise_exception }
end
end
end

0 comments on commit 2740cf3

Please sign in to comment.