[PATCH] git-remote-mediawiki: better error message when HTTP(S) access fails

Subsystems: the rest

STALE3717d

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] git-remote-mediawiki: better error message when HTTP(S) access fails

From: Matthieu Moy <hidden>
Date: 2016-06-15 22:57:25

My use-case is an invalid SSL certificate. Pulling from the wiki with a
recent version of libwww-perl fails, and git-remote-mediawiki gave no
clue about the reason. Give the mediawiki API detailed error message, and
since it is not so informative, hint the user about an invalid SSL
certificate on https:// urls.

Signed-off-by: Matthieu Moy <redacted>
---
 contrib/mw-to-git/git-remote-mediawiki.perl | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index 9c14c1f..5b6e833 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -292,7 +292,13 @@ sub get_mw_all_pages {
 	if (!defined($mw_pages)) {
 		print STDERR "fatal: could not get the list of wiki pages.\n";
 		print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
-		print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
+		if ($url =~ /^https/) {
+		    print STDERR "fatal: make sure '$url/api.php' is a valid page\n";
+		    print STDERR "fatal: and the SSL certificate is correct.\n";
+		} else {
+		    print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
+		}
+		print STDERR "error: " . $mediawiki->{error}->{details} . "\n";
 		exit 1;
 	}
 	foreach my $page (@{$mw_pages}) {
-- 
1.8.3.rc3.8.g5e49f30

Re: [PATCH] git-remote-mediawiki: better error message when HTTP(S) access fails

From: Jeff King <hidden>
Date: 2016-06-15 22:57:28

On Thu, May 23, 2013 at 10:05:03PM +0200, Matthieu Moy wrote:
My use-case is an invalid SSL certificate. Pulling from the wiki with a
recent version of libwww-perl fails, and git-remote-mediawiki gave no
clue about the reason. Give the mediawiki API detailed error message, and
since it is not so informative, hint the user about an invalid SSL
certificate on https:// urls.
This is definitely an improvement, but it seems like it just the tip of
the iceberg.

The call in get_mw_tracked_categories already uses die() with the MW
error code and detailed string. Good. The call you fix here prints a
guess to stderr and exits 1, and your patch improves that. But the call
in get_mw_first_pages does the same broken thing, and is not fixed.
Ditto for get_all_mediafiles. Other calls do not even seem to error
check the result at all, and assume the result is not undef (which I
suspect would produce a perl runtime error).

I wonder if we can do something like:

  our $mw_operation;
  $mediawiki->{config}->{on_error} = sub {
          my $err = "fatal: ";
          if (defined $mw_operation) {
                  $err .= "unable to $mw_operation: ";
          }
          err .= $mediawiki->{error}->{details};
          die "$err\n";
  };

and then callers do not have to worry about error-checking at all. If
they want a nicer human-readable indication of where the error occured,
they can do:

  local $mw_operation = "get the list of remote wiki pages";
  my $mw_pages = $mediawiki->list(...);

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help