git-remote-mediawiki: better error message when HTTP(S) access fails
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 <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matthieu Moy committed
May 29, 2013 at 14:06 UTC
0aa0321212d6b817783616af4ba1353a46b82179
1 file changed
+18
-8
contrib/mw-to-git/git-remote-mediawiki.perl
+18
-8
@@ -238,6 +238,22 @@ sub mw_connect_maybe {
238
}
239
}
240
241
+sub fatal_mw_error {
242
+ my $action = shift;
243
+ print STDERR "fatal: could not $action.\n";
244
+ print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
245
+ if ($url =~ /^https/) {
246
+ print STDERR "fatal: make sure '$url/api.php' is a valid page\n";
247
+ print STDERR "fatal: and the SSL certificate is correct.\n";
248
+ } else {
249
+ print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
250
+ }
251
+ print STDERR "fatal: (error " .
252
+ $mediawiki->{error}->{code} . ': ' .
253
+ $mediawiki->{error}->{details} . ")\n";
254
+ exit 1;
255
+}
256
+
257
## Functions for listing pages on the remote wiki
258
sub get_mw_tracked_pages {
259
my $pages = shift;
@@ -290,10 +306,7 @@ sub get_mw_all_pages {
306
aplimit => 'max'
307
});
308
if (!defined($mw_pages)) {
293
- print STDERR "fatal: could not get the list of wiki pages.\n";
294
- print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
295
- print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
296
- exit 1;
309
+ fatal_mw_error("get the list of wiki pages");
310
}
311
foreach my $page (@{$mw_pages}) {
312
$pages->{$page->{title}} = $page;
@@ -316,10 +329,7 @@ sub get_mw_first_pages {
329
titles => $titles,
330
});
331
if (!defined($mw_pages)) {
319
- print STDERR "fatal: could not query the list of wiki pages.\n";
320
- print STDERR "fatal: '$url' does not appear to be a mediawiki\n";
321
- print STDERR "fatal: make sure '$url/api.php' is a valid page.\n";
322
- exit 1;
332
+ fatal_mw_error("query the list of wiki pages");
333
}
334
while (my ($id, $page) = each(%{$mw_pages->{query}->{pages}})) {
335
if ($id < 0) {