[Bps-public-commit] Prophet branch, master, updated. 06ed5c413831e55329c9b02434ca0f64731b04d0

spang at bestpractical.com spang at bestpractical.com
Mon Jul 20 10:56:17 EDT 2009


The branch, master has been updated
       via  06ed5c413831e55329c9b02434ca0f64731b04d0 (commit)
       via  1e30e4fc4c040553d4d086337de683dc12291d19 (commit)
       via  d10f9d3c0225757b2f430af57701ae1fd4bf7343 (commit)
      from  4b3789db919c8fdafbf8f5811604da2707ed770f (commit)

Summary of changes:
 lib/Prophet/FilesystemReplica.pm |    2 +-
 lib/Prophet/Replica.pm           |    3 +-
 lib/Prophet/Replica/file.pm      |    6 ++-
 lib/Prophet/Replica/sqlite.pm    |   28 +++++++++++++---
 t/malformed-url.t                |   67 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 97 insertions(+), 9 deletions(-)
 create mode 100644 t/malformed-url.t

- Log -----------------------------------------------------------------
commit d10f9d3c0225757b2f430af57701ae1fd4bf7343
Author: Christine Spang <spang at mit.edu>
Date:   Fri Jul 17 15:34:52 2009 +0100

    Better error message when we fail to open SQLite replica dbs.

diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index bb00d1c..1b1a09e 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -15,7 +15,12 @@ has dbh => (
     lazy => 1,
     default => sub {
         my $self = shift;
-        DBI->connect( "dbi:SQLite:" . $self->db_file , undef, undef, {RaiseError =>1, AutoCommit => 1 });
+        eval {
+            DBI->connect( "dbi:SQLite:" . $self->db_file , undef, undef, {RaiseError =>1, AutoCommit => 1 });
+        };
+        if ($@) {
+            die "Unable to open the database file '".$self->db_file."'. Is this a readable SQLite replica?\n";
+        }
      }
 
 

commit 1e30e4fc4c040553d4d086337de683dc12291d19
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jul 20 14:59:46 2009 +0100

    Better error messages when we use bad URL syntax.

diff --git a/lib/Prophet/FilesystemReplica.pm b/lib/Prophet/FilesystemReplica.pm
index f917bc2..885b4d6 100644
--- a/lib/Prophet/FilesystemReplica.pm
+++ b/lib/Prophet/FilesystemReplica.pm
@@ -293,7 +293,7 @@ sub lwp_get {
             return $response->content;
         }
     }
-    warn "Could not fetch " . $url . " - " . $response->status_line;
+    warn "Could not fetch " . $url . " - " . $response->status_line . "\n";
     return undef;
 }
           
diff --git a/lib/Prophet/Replica.pm b/lib/Prophet/Replica.pm
index 7b7f790..7aa4d3c 100644
--- a/lib/Prophet/Replica.pm
+++ b/lib/Prophet/Replica.pm
@@ -79,7 +79,8 @@ sub get_handle {
 
     if ( !$new_class ) {
         $class->log_fatal(
-            "I don't know how to handle the replica URL you provided - '@{[ $args{url}]}'"
+            "I don't know how to handle the replica URL you provided - '@{[ $args{url}]}'."
+            ."\nIs your syntax correct?"
         );
     }
 
diff --git a/lib/Prophet/Replica/file.pm b/lib/Prophet/Replica/file.pm
index 6de4e43..0883dd5 100644
--- a/lib/Prophet/Replica/file.pm
+++ b/lib/Prophet/Replica/file.pm
@@ -5,7 +5,7 @@ sub scheme { 'file' }
 
 sub replica_exists {
     my $self = shift;
-    return 0 unless -d $self->fs_root;
+    return 0 unless defined $self->fs_root && -d $self->fs_root;
     return 0 unless -e File::Spec->catfile( $self->fs_root => 'database-uuid' );
     return 1;
 }
@@ -31,7 +31,9 @@ sub new {
     if (my $default_type =  $possible{$args{app_handle}->default_replica_type} ) { 
         return $default_type;
     } else {
-        $class->log_fatal("I don't know what to do with the Prophet replica type you specified: ".$args{app_handle}->default_replica_type);
+        $class->log_fatal("I don't know what to do with the Prophet replica ".
+            "type you specified: ".$args{app_handle}->default_replica_type.
+            "\nIs your URL syntax correct?");
     }
 }
 
diff --git a/lib/Prophet/Replica/sqlite.pm b/lib/Prophet/Replica/sqlite.pm
index 1b1a09e..3ad6b28 100644
--- a/lib/Prophet/Replica/sqlite.pm
+++ b/lib/Prophet/Replica/sqlite.pm
@@ -15,18 +15,31 @@ has dbh => (
     lazy => 1,
     default => sub {
         my $self = shift;
+        my $dbh;
+        die "I couldn't determine a filesystem root from the given URL.\n"
+        ."Correct syntax is (sqlite:)file:///replica/root .\n"
+            unless $self->db_file;
         eval {
-            DBI->connect( "dbi:SQLite:" . $self->db_file , undef, undef, {RaiseError =>1, AutoCommit => 1 });
+            $dbh = DBI->connect(
+                "dbi:SQLite:" . $self->db_file,
+                undef, undef,
+                { RaiseError => 1, AutoCommit => 1 },
+            );
         };
         if ($@) {
-            die "Unable to open the database file '".$self->db_file."'. Is this a readable SQLite replica?\n";
+            die "Unable to open the database file '".$self->db_file
+                ."'. Is this a readable SQLite replica?\n";
         }
+        return $dbh;
      }
+);
 
+sub db_file {
+    my $self = shift;
+    my $fs_root = $self->fs_root;
 
-    );
-
-sub db_file { shift->fs_root ."/db.sqlite"}
+    return defined $fs_root ? "$fs_root/db.sqlite" : undef;
+}
 
 has '+db_uuid' => (
     lazy    => 1,
@@ -162,7 +175,7 @@ Returns false otherwise.
 
 sub replica_exists {
     my $self = shift;
-    return -f $self->db_file ? 1 : 0;
+    return defined $self->db_file && -f $self->db_file ? 1 : 0;
 }
 
 =head2 replica_version

commit 06ed5c413831e55329c9b02434ca0f64731b04d0
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jul 20 15:48:29 2009 +0100

    Tests for bad URL syntax.

diff --git a/t/malformed-url.t b/t/malformed-url.t
new file mode 100644
index 0000000..5e4f04c
--- /dev/null
+++ b/t/malformed-url.t
@@ -0,0 +1,67 @@
+use warnings;
+use strict;
+
+use Test::More tests => 6;
+use File::Temp qw(tempdir);
+use Test::Script::Run qw(run_script);
+
+$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG}  ) . '/repo-' . $$;
+
+# try to make prophet clone explode by feeding it bogus URLs
+
+(undef, undef, my $error) = run_script( 'prophet', ['clone', '--from', 'malformed-url'] );
+is( $error, <<EOM
+I don't know how to handle the replica URL you provided - 'malformed-url'.
+Is your syntax correct?
+EOM
+, 'malformed url errors out' );
+
+$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG}  ) . '/repo-' . $$;
+(undef, undef, $error)
+    = run_script( 'prophet', ['clone', '--from', 'sqlite:foo'] );
+is( $error, <<EOM
+I couldn't determine a filesystem root from the given URL.
+Correct syntax is (sqlite:)file:///replica/root .
+EOM
+, 'sqlite:foo errors out' );
+
+# sqlite is default replica type
+$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG}  ) . '/repo-' . $$;
+(undef, undef, $error)
+    = run_script( 'prophet', ['clone', '--from', 'file:foo'] );
+is( $error, <<EOM
+I couldn't determine a filesystem root from the given URL.
+Correct syntax is (sqlite:)file:///replica/root .
+EOM
+, 'file:foo errors out' );
+
+$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG}  ) . '/repo-' . $$;
+(undef, undef, $error)
+    = run_script( 'prophet', ['clone', '--from', 'sqlite://file://foo'] );
+is( $error, <<EOM
+I couldn't determine a filesystem root from the given URL.
+Correct syntax is (sqlite:)file:///replica/root .
+EOM
+, 'sqlite://file://foo errors out' );
+
+$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG}  ) . '/repo-' . $$;
+(undef, undef, $error)
+    = run_script( 'prophet',
+        ['clone', '--from', 'sqlite:http://www.example.com/sd'] );
+is( $error, <<EOM
+I couldn't determine a filesystem root from the given URL.
+Correct syntax is (sqlite:)file:///replica/root .
+EOM
+, 'SQLite replicas can\'t be via http' );
+
+$ENV{'PROPHET_REPO'} = tempdir( CLEANUP => ! $ENV{PROPHET_DEBUG}  ) . '/repo-' . $$;
+(undef, my $out, undef)
+    = run_script( 'prophet',
+        ['clone', '--from',
+        'prophet:http://web.mit.edu/spang/Public/tmp/bogus-sd'] );
+# Don't test fetch errors because the user running these tests may or may not
+# have network, so they won't always be the same.
+is( $out,
+    "The source replica 'http://web.mit.edu/spang/Public/tmp/bogus-sd' doesn't exist or is unreadable.",
+    'prophet replicas *can* be via http',
+);

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list