aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-25 13:16:00 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-10-25 13:16:00 +0000
commitb86c75d8f8e2d8993acb6ae1199aaf923271a7f6 (patch)
tree3ae02e42e52d7f4780be06cf29f7a8a453048cca
parentddf2a289d8a4cd0784fce235ad923e35834bb16d (diff)
downloadpaludis-b86c75d8f8e2d8993acb6ae1199aaf923271a7f6.tar.gz
paludis-b86c75d8f8e2d8993acb6ae1199aaf923271a7f6.tar.xz
Extend Paludis to Ruby exception conversion
-rw-r--r--ruby/environment_TEST.rb2
-rw-r--r--ruby/package_database_TEST.rb2
-rw-r--r--ruby/paludis_ruby.cc16
3 files changed, 18 insertions, 2 deletions
diff --git a/ruby/environment_TEST.rb b/ruby/environment_TEST.rb
index 5eba5f7..545e4a8 100644
--- a/ruby/environment_TEST.rb
+++ b/ruby/environment_TEST.rb
@@ -215,7 +215,7 @@ class Paludis
def test_mask_reasons_no_such_repo
p = PackageDatabaseEntry.new("foo/bar", VersionSpec.new("1.0"), "nosuchrepo")
- assert_raise RuntimeError do
+ assert_raise Paludis::NoSuchRepositoryError do
env.mask_reasons p
end
end
diff --git a/ruby/package_database_TEST.rb b/ruby/package_database_TEST.rb
index dca941d..a21f6fe 100644
--- a/ruby/package_database_TEST.rb
+++ b/ruby/package_database_TEST.rb
@@ -106,7 +106,7 @@ class Paludis
def test_fetch_repository
assert_equal "testrepo", db.fetch_repository("testrepo").name
- assert_raise RuntimeError do
+ assert_raise Paludis::NoSuchRepositoryError do
db.fetch_repository("barrepo")
end
end
diff --git a/ruby/paludis_ruby.cc b/ruby/paludis_ruby.cc
index 77b24c1..c2fc841 100644
--- a/ruby/paludis_ruby.cc
+++ b/ruby/paludis_ruby.cc
@@ -41,6 +41,10 @@ namespace
static VALUE c_master_class;
static VALUE c_name_error;
static VALUE c_package_dep_atom_error;
+ static VALUE c_package_database_error;
+ static VALUE c_package_database_lookup_error;
+ static VALUE c_no_such_package_error;
+ static VALUE c_no_such_repository_error;
}
RegisterRubyClass::RegisterRubyClass() :
@@ -74,6 +78,14 @@ void paludis::ruby::exception_to_ruby_exception(const std::exception & ee)
rb_raise(c_name_error, dynamic_cast<const paludis::NameError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::PackageDepAtomError *>(&ee))
rb_raise(c_package_dep_atom_error, dynamic_cast<const paludis::PackageDepAtomError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::NoSuchRepositoryError *>(&ee))
+ rb_raise(c_no_such_repository_error, dynamic_cast<const paludis::NoSuchRepositoryError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::NoSuchPackageError *>(&ee))
+ rb_raise(c_no_such_package_error, dynamic_cast<const paludis::NoSuchPackageError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::PackageDatabaseLookupError *>(&ee))
+ rb_raise(c_package_database_lookup_error, dynamic_cast<const paludis::PackageDatabaseLookupError *>(&ee)->message().c_str());
+ else if (0 != dynamic_cast<const paludis::PackageDatabaseError *>(&ee))
+ rb_raise(c_package_database_error, dynamic_cast<const paludis::PackageDatabaseError *>(&ee)->message().c_str());
else if (0 != dynamic_cast<const paludis::Exception *>(&ee))
rb_raise(rb_eRuntimeError, "Caught paludis::Exception: %s (%s)",
dynamic_cast<const paludis::Exception *>(&ee)->message().c_str(), ee.what());
@@ -118,6 +130,10 @@ extern "C"
c_master_class = rb_define_class("Paludis", rb_cObject);
c_name_error = rb_define_class_under(c_master_class, "NameError", rb_eRuntimeError);
c_package_dep_atom_error = rb_define_class_under(c_master_class, "PackageDepAtomError", rb_eRuntimeError);
+ c_package_database_error = rb_define_class_under(c_master_class, "PackageDatabaseError", rb_eRuntimeError);
+ c_package_database_lookup_error = rb_define_class_under(c_master_class, "PackageDatabaseLookupError", c_package_database_error);
+ c_no_such_package_error = rb_define_class_under(c_master_class, "NoSuchPackageError", c_package_database_lookup_error);
+ c_no_such_repository_error = rb_define_class_under(c_master_class, "NoSuchRepositoryError", c_package_database_lookup_error);
rb_define_const(c_master_class, "Version", rb_str_new2((stringify(PALUDIS_VERSION_MAJOR) + "."
+ stringify(PALUDIS_VERSION_MINOR) + "." + stringify(PALUDIS_VERSION_MICRO)).c_str()));