Carp -- shortmess and longmess

Ask a Question related to PERL Modules, Design and Development.

  1. #1

    Default Carp -- shortmess and longmess

    perldoc Carp says:

    carp - warn of errors (from perspective of caller)
    cluck - warn of errors with stack backtrace
    (not exported by default)
    croak - die of errors (from perspective of caller)
    confess - die of errors with stack backtrace
    shortmess - return the message that carp and croak produce
    longmess - return the message that cluck and confess produce

    but this is not how it appears to work. I created a test program
    based on the examples in the manual:

    --- begin carp.pl ---
    use Carp qw(croak cluck);

    sub foo {
    cluck "This is how we got here!";
    print Carp::shortmess("This will have caller's details added");
    print Carp::longmess("This will have stack backtrace added");
    croak "We're outta here!";
    }

    sub bar {
    foo();
    }

    bar();
    --- end carp.pl ---

    When I run this program, I get the following output:

    This is how we got here! at carp.pl line 4
    main::foo() called at carp.pl line 11
    main::bar() called at carp.pl line 14
    This will have caller's details added at carp.pl line 5
    main::foo() called at carp.pl line 11
    main::bar() called at carp.pl line 14
    This will have stack backtrace added at carp.pl line 11
    main::bar() called at carp.pl line 14
    We're outta here! at carp.pl line 7
    main::foo() called at carp.pl line 11
    main::bar() called at carp.pl line 14

    The message from cluck seems to be OK -- it prints the backtrace,
    as it should. The next two, shortmess and longmess, appear
    to do the opposite of what they should. shortmess prints the
    longest message, backtrace and everything, while longmess only
    prints the bottom of the stack. It should've been the other
    way around, right? croak also prints the full backtrace, which,
    if I understand the manual correctly, is incorrect.

    In summary: carp, cluck, croak and confess all print the full
    backtrace (same as shortmess), and the longmess message is
    never used.

    Verified on the following systems:

    Custom built Perl 5.8.4 (-Duse64bitint -des), Caro 1.02
    Custom built Perl 5.8.5 (-Duse64bitint -des), Carp 1.03
    Slackware 10's Perl 5.8.4, Carp 1.02
    Red Hat Enterprise Linux WS release 3's Perl 5.8.4, Carp 1.02

    Is this a known bug, or should I report it with perlbug?

    --
    Haakon
    Haakon Riiser Guest

  2. Similar Questions and Discussions

    1. ANN: Win32::EventLog::Carp 1.30 released
      The latest version of Win32::EventLog::Carp has been uploaded to PAUSE and should begin showing up in a CPAN mirror near you at ...
    2. No $VERSION for Carp modules
      I was documenting the list of modules and module versions that we use in our applications, and noticed that Carp does not have a $VERSION defined....
    3. Getting croak or carp into variable ?
      Hello List, I am using a module that does use Carp; and you can specify whther you want croak or carp on an error Which is cool. But there is...
    4. CGI::Carp Problems
      Hi all, I'm fairly new to Perl so excuse how stupid i sound. I have this perl script that needs CGI, so Carp.pm gets installed I got the...
    5. $SIG{__DIE__} doesn't make sense when using CGI::Carp
      Me and my cgi-script have the following problem. I'm using the package CGI::Carp (which installs internally some $SIG{__DIE___} handlers). In...
  3. #2

    Default Re: Carp -- shortmess and longmess

    Haakon Riiser <hakonrk@fys.uio.no> wrote in comp.lang.perl.misc:
    > perldoc Carp says:
    >
    > carp - warn of errors (from perspective of caller)
    > cluck - warn of errors with stack backtrace
    > (not exported by default)
    > croak - die of errors (from perspective of caller)
    > confess - die of errors with stack backtrace
    > shortmess - return the message that carp and croak produce
    > longmess - return the message that cluck and confess produce
    >
    > but this is not how it appears to work. I created a test program
    > based on the examples in the manual:
    >
    > --- begin carp.pl ---
    > use Carp qw(croak cluck);
    >
    > sub foo {
    > cluck "This is how we got here!";
    > print Carp::shortmess("This will have caller's details added");
    > print Carp::longmess("This will have stack backtrace added");
    > croak "We're outta here!";
    > }
    >
    > sub bar {
    > foo();
    > }
    >
    > bar();
    > --- end carp.pl ---
    >
    > When I run this program, I get the following output:
    >
    > This is how we got here! at carp.pl line 4
    > main::foo() called at carp.pl line 11
    > main::bar() called at carp.pl line 14
    > This will have caller's details added at carp.pl line 5
    > main::foo() called at carp.pl line 11
    > main::bar() called at carp.pl line 14
    > This will have stack backtrace added at carp.pl line 11
    > main::bar() called at carp.pl line 14
    > We're outta here! at carp.pl line 7
    > main::foo() called at carp.pl line 11
    > main::bar() called at carp.pl line 14
    >
    > The message from cluck seems to be OK -- it prints the backtrace,
    > as it should. The next two, shortmess and longmess, appear
    > to do the opposite of what they should. shortmess prints the
    > longest message, backtrace and everything, while longmess only
    > prints the bottom of the stack. It should've been the other
    > way around, right? croak also prints the full backtrace, which,
    > if I understand the manual correctly, is incorrect.
    >
    > In summary: carp, cluck, croak and confess all print the full
    > backtrace (same as shortmess), and the longmess message is
    > never used.
    >
    > Verified on the following systems:
    >
    > Custom built Perl 5.8.4 (-Duse64bitint -des), Caro 1.02
    > Custom built Perl 5.8.5 (-Duse64bitint -des), Carp 1.03
    > Slackware 10's Perl 5.8.4, Carp 1.02
    > Red Hat Enterprise Linux WS release 3's Perl 5.8.4, Carp 1.02
    >
    > Is this a known bug, or should I report it with perlbug?
    Carp tries to find a location on the call stack where it believes
    the error was introduced. When it can't find one, it switches to
    a full backtrace on its own accord. This seems to be happening here.

    The error location is always a point where a call crosses module
    boundaries. Give it such a call, and the results will be more
    consistent:

    use Carp;

    one();
    exit;

    sub one { Foo::two() }

    package Foo;

    sub two {
    print Carp::shortmess( 'shortmess');
    print Carp::longmess( 'longmess');
    }

    Anno
    Anno Siegel Guest

  4. #3

    Default Re: Carp -- shortmess and longmess

    [Anno Siegel]
    > Carp tries to find a location on the call stack where it believes
    > the error was introduced. When it can't find one, it switches to
    > a full backtrace on its own accord. This seems to be happening here.
    >
    > The error location is always a point where a call crosses module
    > boundaries. Give it such a call, and the results will be more
    > consistent:
    > [...]
    Thanks; in the future, I should probably read beyond the first
    paragraph before I consider filing bug reports. I thought the
    summary was so clear, that I didn't bother to look to the second
    paragraph, which begins: "Here is a more complete description of
    how shortmess works." Embarrassing! :-)

    --
    Haakon
    Haakon Riiser Guest

  5. #4

    Default Re: Carp -- shortmess and longmess

    Haakon Riiser (hakonrk@fys.uio.no) wrote on MMMCMLXXXII September
    MCMXCIII in <URL:news:slrncg9ua0.emo.hakonrk@s.hn.org>:
    `' perldoc Carp says:
    `'
    `' carp - warn of errors (from perspective of caller)
    `' cluck - warn of errors with stack backtrace
    `' (not exported by default)
    `' croak - die of errors (from perspective of caller)
    `' confess - die of errors with stack backtrace
    `' shortmess - return the message that carp and croak produce
    `' longmess - return the message that cluck and confess produce
    `'
    `' but this is not how it appears to work. I created a test program
    `' based on the examples in the manual:
    `'
    `' --- begin carp.pl ---
    `' use Carp qw(croak cluck);
    `'
    `' sub foo {
    `' cluck "This is how we got here!";
    `' print Carp::shortmess("This will have caller's details added");
    `' print Carp::longmess("This will have stack backtrace added");
    `' croak "We're outta here!";
    `' }
    `'
    `' sub bar {
    `' foo();
    `' }
    `'
    `' bar();
    `' --- end carp.pl ---
    `'
    `' When I run this program, I get the following output:
    `'
    `' This is how we got here! at carp.pl line 4
    `' main::foo() called at carp.pl line 11
    `' main::bar() called at carp.pl line 14
    `' This will have caller's details added at carp.pl line 5
    `' main::foo() called at carp.pl line 11
    `' main::bar() called at carp.pl line 14
    `' This will have stack backtrace added at carp.pl line 11
    `' main::bar() called at carp.pl line 14
    `' We're outta here! at carp.pl line 7
    `' main::foo() called at carp.pl line 11
    `' main::bar() called at carp.pl line 14
    `'
    `' The message from cluck seems to be OK -- it prints the backtrace,
    `' as it should. The next two, shortmess and longmess, appear
    `' to do the opposite of what they should. shortmess prints the
    `' longest message, backtrace and everything, while longmess only
    `' prints the bottom of the stack. It should've been the other
    `' way around, right? croak also prints the full backtrace, which,
    `' if I understand the manual correctly, is incorrect.

    No, it's not incorrect. You have to read the manual
    carefully. longmess/cluck/confess return the stacktrace. Always.
    shortmess/carp/croak print the first entry in the stacktrace that isn't
    considered "safe". But when everything is "safe", it defaults to printing
    the entire stacktrace. The manual also list what is considered safe,
    and point 1 says any call into the same package is considered safe.

    A small change to your program shows the difference:

    #!/usr/bin/perl

    use strict;
    use warnings;
    no warnings qw /syntax/;

    use Carp qw(croak cluck);

    sub foo {
    cluck "This is how we got here!";
    print Carp::shortmess("This will have caller's details added");
    print Carp::longmess("This will have stack backtrace added");
    croak "We're outta here!";
    }

    package Alien;
    sub bar {
    main::foo();
    }

    package main;
    Alien::bar();
    __END__
    This is how we got here! at /tmp/f line 11
    main::foo() called at /tmp/f line 19
    Alien::bar() called at /tmp/f line 23
    This will have caller's details added at /tmp/f line 19
    This will have stack backtrace added at /tmp/f line 19
    Alien::bar() called at /tmp/f line 23
    We're outta here! at /tmp/f line 19


    Abigail
    --
    print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
    v80.101.114.108.32, v72.97.99.107.101.114.10;
    Abigail Guest

  6. #5

    Default Re: Carp -- shortmess and longmess

    Quote Originally Posted by Abigail View Post
    A small change to your program shows the difference:

    #!/usr/bin/perl

    use strict;
    use warnings;
    no warnings qw /syntax/;

    use Carp qw(croak cluck);

    sub foo {
    cluck "This is how we got here!";
    print Carp::shortmess("This will have caller's details added");
    print Carp::longmess("This will have stack backtrace added");
    croak "We're outta here!";
    }

    package Alien;
    sub bar {
    main::foo();
    }

    package main;
    Alien::bar();
    __END__
    This is how we got here! at /tmp/f line 11
    main::foo() called at /tmp/f line 19
    Alien::bar() called at /tmp/f line 23
    This will have caller's details added at /tmp/f line 19
    This will have stack backtrace added at /tmp/f line 19
    Alien::bar() called at /tmp/f line 23
    We're outta here! at /tmp/f line 19

    The longmess version appears to only print out the Alien::bar() call; shouldn't it also display the subsequent call to main::foo() as well?
    Anon Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139