Skip to content

Commit

Permalink
more fixup, show a stack trace when we give a deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
slyphon committed May 4, 2012
1 parent 51572b4 commit 04df860
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
10 changes: 2 additions & 8 deletions lib/zookeeper/client.rb
@@ -1,16 +1,10 @@
# figure out what platform we're on
# this way there's no ambiguity about which file to include
# or which class we're subclassing.

if defined?(::JRUBY_VERSION)
# $stderr.puts "Loading the jruby extensions"
# $LOAD_PATH.unshift(File.expand_path('../../../java', __FILE__)).uniq!
# require 'java_base'

require_relative('../../java/java_base')
else
# $stderr.puts "adding the C extensions"
# $LOAD_PATH.unshift(File.expand_path('../../../ext', __FILE__)).uniq!
# require 'zookeeper_base'

require_relative('../../ext/zookeeper_base')
end

Expand Down
19 changes: 15 additions & 4 deletions lib/zookeeper/exceptions.rb
Expand Up @@ -3,17 +3,25 @@ module Exceptions
include Constants

class ZookeeperException < StandardError
CONST_MISSING_WARNING = <<-EOS

unless defined?(CONST_MISSING_WARNING)

CONST_MISSING_WARNING = <<-EOS
------------------------------------------------------------------------------------------
WARNING! THE ZOOKEEPER NAMESPACE HAS CHNAGED AS OF 1.0!
Please update your code to use the new heirarchy!
The constant that got you this was ZookeeperExceptions::ZookeeperException::%s
stacktrace:
%s
------------------------------------------------------------------------------------------
EOS
EOS
end

# NOTE(slyphon): Since 0.4 all of the ZookeeperException subclasses were
# defined inside of ZookeeperException, which always seemed well, icky.
Expand All @@ -23,7 +31,10 @@ class ZookeeperException < StandardError
def self.const_missing(const)
if Zookeeper::Exceptions.const_defined?(const)

Zookeeper.deprecation_warning(CONST_MISSING_WARNING % [const.to_s])
stacktrace = caller[0..-2].reject {|n| n =~ %r%/rspec/% }.map { |n| "\t#{n}" }.join("\n")

Zookeeper.deprecation_warning(CONST_MISSING_WARNING % [const.to_s, stacktrace])


Zookeeper::Exceptions.const_get(const).tap do |const_val|
self.const_set(const, const_val)
Expand Down Expand Up @@ -67,7 +78,7 @@ class ShuttingDownException < ZookeeperException; end
class DataTooLargeException < ZookeeperException; end

# yes, make an alias, this is the way zookeeper refers to it
ExpiredSession = SessionExpired
ExpiredSession = SessionExpired unless defined?(ExpiredSession)

def self.by_code(code)
case code
Expand Down
2 changes: 1 addition & 1 deletion spec/shared/connection_examples.rb
Expand Up @@ -129,7 +129,7 @@

describe 'bad arguments' do
it %[should barf with a BadArguments error] do
lambda { zk.get(:bad_arg => 'what!?') }.should raise_error(ZookeeperExceptions::ZookeeperException::BadArguments)
lambda { zk.get(:bad_arg => 'what!?') }.should raise_error(Zookeeper::Exceptions::BadArguments)
end
end
end # get
Expand Down

0 comments on commit 04df860

Please sign in to comment.