Permalink
Browse files

* Removed LoadError trap from bin/sequel.

* Replaced Sequel::Error::InvalidDatabaseScheme with Sequel::Error::AdapterNotFound.
* Sequel::Database.adapter_class now raises an AdapterNotFound exception if the adapter file can't be found or if the adapter isn't contained in the file.
  • Loading branch information...
1 parent a4f18e3 commit 3da4f9f5e66f5c849cc8db062d5a0af1b568f0a1 @codahale codahale committed Dec 30, 2007
Showing with 22 additions and 15 deletions.
  1. +0 −3 core/bin/sequel
  2. +16 −6 core/lib/sequel/database.rb
  3. +3 −3 core/lib/sequel/exceptions.rb
  4. +3 −3 core/spec/database_spec.rb
View
@@ -23,9 +23,6 @@ end
begin
DB = Sequel.connect db
-rescue LoadError => e
- puts "Failed to load adapter: #{e.message}"
- exit
rescue => e
puts e.message
exit
@@ -371,13 +371,23 @@ def self.uri_to_options(uri)
end
def self.adapter_class(scheme)
- scheme = scheme.to_s =~ /\-/ ? scheme.to_s.gsub('-', '_').to_sym : scheme.to_sym
- unless c = @@adapters[scheme.to_sym]
- require File.join(File.dirname(__FILE__), "adapters/#{scheme}")
- c = @@adapters[scheme.to_sym]
+ adapter_name = scheme.to_s =~ /\-/ ? scheme.to_s.gsub('-', '_').to_sym : scheme.to_sym
+ scheme = scheme.to_sym
+
+ if (klass = @@adapters[scheme]).nil?
+ # attempt to load the adapter file
+ begin
+ require File.join(File.dirname(__FILE__), "adapters/#{scheme}")
+ rescue LoadError => e
+ raise Error::AdapterNotFound, "Could not load #{scheme} adapter:\n #{e.message}"
+ end
+
+ # make sure we actually loaded the adapter
+ if (klass = @@adapters[scheme]).nil?
+ raise Error::AdapterNotFound, "Could not load #{scheme} adapter"
+ end
end
- raise Error::InvalidDatabaseScheme, "Invalid database scheme" unless c
- c
+ return klass
end
# call-seq:
@@ -5,8 +5,6 @@ class Error < StandardError
# Rollback is a special error used to rollback a transactions.
# A transaction block will catch this error and wont pass further up the stack.
class Rollback < Error ; end
-
- class InvalidDatabaseScheme < Error; end
# Represents an invalid value stored in the database.
class InvalidValue < Error ; end
@@ -26,7 +24,9 @@ class NoExistingFilter < Error ; end
class InvalidJoinType < Error ; end
class WorkerStop < RuntimeError ; end
-
+
+ # Raised when Sequel is unable to load a specified adapter.
+ class AdapterNotFound < Error ; end
end
end
@@ -545,15 +545,15 @@ class CCC < Sequel::Database
context "An unknown database scheme" do
specify "should raise an error in Sequel::Database.connect" do
- proc {Sequel::Database.connect('ddd://localhost/db')}.should raise_error(LoadError)
+ proc {Sequel::Database.connect('ddd://localhost/db')}.should raise_error(Sequel::Error::AdapterNotFound)
end
specify "should raise an error in Sequel.connect" do
- proc {Sequel.connect('ddd://localhost/db')}.should raise_error(LoadError)
+ proc {Sequel.connect('ddd://localhost/db')}.should raise_error(Sequel::Error::AdapterNotFound)
end
specify "should raise an error in Sequel.open" do
- proc {Sequel.open('ddd://localhost/db')}.should raise_error(LoadError)
+ proc {Sequel.open('ddd://localhost/db')}.should raise_error(Sequel::Error::AdapterNotFound)
end
end

0 comments on commit 3da4f9f

Please sign in to comment.