Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the WWW-Shorten CPAN distribution.

Report information
The Basics
Id: 75444
Status: resolved
Priority: 0/
Queue: WWW-Shorten

People
Owner: DAVECROSS [...] cpan.org
Requestors: KENTNL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 3.03
Fixed in: (no value)



Subject: Better feedback on error conditions.
Hi there,

 

I was installing WWW::Shorten today and a test failed. I suspected it was due to a service outage but there was no way to tell what was going wrong.

It would be nice if there were some sort of error feedback other than getting back 'undef'  .

Test output was as follows: 

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

t/00load.t .......... ok
t/00load_a.t ........ ok
t/00load_b.t ........ ok
t/00noexp.t ......... ok
t/00sig.t ........... ok
Show quoted text

# Test::More 0.98
# LWP::UserAgent 6.04
t/01version.t ....... ok
t/98pod-coverage.t .. ok
t/99pod.t ........... ok
t/linktoolbot.t ..... ok
t/linkz.t ........... ok
t/masl.t ............ ok
t/metamark.t ........ ok
t/newnames.t ........ ok
t/tinyclick.t ....... ok
t/tinylink.t ........ ok
Use of uninitialized value $return in pattern match (m//) at t/tinyurl.t line 7.
Use of uninitialized value $code in concatenation (.) or string at t/tinyurl.t line 9.

Show quoted text
#   Failed test 'make it shorter'
#   at t/tinyurl.t line 9.
#          got: undef
#     expected: 'http://tinyurl.com/'
Use of uninitialized value $code in concatenation (.) or string at t/tinyurl.t line 10.

Show quoted text
#   Failed test 'make it longer'
#   at t/tinyurl.t line 10.
#          got: undef
#     expected: 'http://search.cpan.org/dist/WWW-Shorten/'
No TinyURL key / URL passed to makealongerlink at t/tinyurl.t line 11.
Show quoted text
# Looks like you planned 6 tests but ran 3.
# Looks like you failed 2 tests of 3 run.
# Looks like your test exited with 255 just after 3.
t/tinyurl.t .........
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 5/6 subtests

Test Summary Report
-------------------
t/tinyurl.t       (Wstat: 65280 Tests: 3 Failed: 2)
  Failed tests:  2-3
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 6 tests but ran 3.

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

So I ripped the code to shreds so I could see what was going on, and yep, as I suspected, the service itself was reporting unavailable.

 

perl /tmp/tiny.pl
Use of uninitialized value $v in concatenation (.) or string at /tmp/tiny.pl line 23.
do {
  my $a = bless({
    _content => "ERROR",
    _headers => bless({
      "client-date"              => "Thu, 01 Mar 2012 04:12:32 GMT",
      "client-peer"              => "64.62.243.89:80",
      "client-response-num"      => 1,
      "client-transfer-encoding" => ["chunked"],
      "connection"               => "close",
      "content-type"             => "text/html",
      "date"                     => "Thu, 01 Mar 2012 04:12:32 GMT",
      "server"                   => "TinyURL/1.6",
      "x-powered-by"             => "PHP/5.3.8",
    }, "HTTP::Headers"),
    _msg => "Service Not Available",
    _protocol => "HTTP/1.1",
    _rc => 503,
    _request => bless({
      _content => "url=http%3A%2F%2Fduckduckgo.com&source=PerlAPI-0.01",
      _headers => bless({
        "content-length" => 51,
        "content-type"   => "application/x-www-form-urlencoded",
        "user-agent"     => "main/",
      }, "HTTP::Headers"),
      _method => "POST",
      _uri => bless(do{\(my $o = "http://tinyurl.com/api-create.php")}, "URI::http"),
      _uri_canonical => 'fix',
    }, "HTTP::Request"),
  }, "HTTP::Response");
  $a->{_request}{_uri_canonical} = \${$a->{_request}{_uri}};
  $a;
} at /tmp/tiny.pl line 41.

 

 

Attached is the script I generated based on the TinyURL shortener to get this diagnosis if it proves helpful.

 

Thanks.

 

-- Kent

Subject: tiny.pl
#!/usr/bin/env perl use strict; use warnings; # FILENAME: tiny.pl # CREATED: 01/03/12 17:07:37 by Kent Fredric (kentnl) <kentfredric@gmail.com> # ABSTRACT: TinyURL test use Carp; use LWP; use Data::Dump qw( pp ); my $VERSION = '0.01'; my $ua; sub ua { my $self = shift; return $ua if defined $ua; my $v = $self->VERSION(); $ua = LWP::UserAgent->new( env_proxy => 1, timeout => 30, agent => "$self/$v", requests_redirectable => [], ); return $ua; } sub makeashorterlink ($) { my $url = shift or croak 'No URL passed to makeashorterlink'; my $ua = __PACKAGE__->ua(); my $tinyurl = 'http://tinyurl.com/api-create.php'; my $resp = $ua->post($tinyurl, [ url => $url, source => "PerlAPI-$VERSION", ]); if ( not $resp->is_success ) { die pp( $resp ); } my $content = $resp->content; if ( $content =~ /Error/ ) { die pp ( $content ); } if ($resp->content =~ m!(\Qhttp://tinyurl.com/\E\w+)!x) { return $1; } return; } die pp( makeashorterlink("http://duckduckgo.com") );
Yes, that's definitely a problem. I've been considering it for some time. It's tied in with the whole "what should we do if we don't have an internet connection" question. Thanks for your program. I'll see what I can grab from it.
Version 3.03 (now on CPAN) fixes this by dying with a suitable error message if we get an error response.