| 1 | # This code is part of Perl distribution Log-Report version 1.46. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2007-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Log::Report::Die;{ | ||||||||||||||||||||||||||||
| 13 | 17 | our $VERSION = '1.46'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 17 | ▶ | use parent 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 17 | our @EXPORT = qw/die_decode exception_decode/; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 17 | ▶ | use POSIX qw/locale_h/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #-------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub die_decode($%) | ||||||||||||||||||||||||||||
| 28 | 18 | ▶ | { my ($text, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
die_decode: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 18 | my @text = split /\n/, $text; | |||||||||||||||||||||||||||
| 31 | 18 | ▶ | @text or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 18 | chomp $text[-1]; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # Try to catch the error directly, to remove it from the error text | ||||||||||||||||||||||||||||
| 35 | 18 | my %opt = (errno => $! + 0); | |||||||||||||||||||||||||||
| 36 | 18 | my $err = "$!"; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 18 | ▶ | if($text[0] =~ s/ at (.+) line (\d+)\.?$// ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 39 | 11 | { $opt{location} = [undef, $1, $2, undef]; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | ▶ | elsif(@text > 1 && $text[1] =~ m/^\s*at (.+) line (\d+)\.?$/ ) | |||||||||||||||||||||||||||
|
Condition100%3/3
@text > 1 and $text[1] =~ /^\s*at (.+) line (\d+)\.?$/
MC/DC100%2/2
@text > 1 and $text[1] =~ /^\s*at (.+) line (\d+)\.?$/
@text > 1
$text[1] =~ /^\s*at (.+) line (\d+)\.?$/
Truth table100%3/3
A and B
A= @text > 1B= $text[1] =~ /^\s*at (.+) line (\d+)\.?$/
| |||||||||||||||||||||||||||||
| 42 | { # sometimes people carp/confess with \n, folding the line | ||||||||||||||||||||||||||||
| 43 | 4 | $opt{location} = [undef, $1, $2, undef]; | |||||||||||||||||||||||||||
| 44 | 4 | splice @text, 1, 1; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | $text[0] =~ s/\s*[.:;]?\s*$err\s*$// # the $err is translation sensitive | ||||||||||||||||||||||||||||
| 48 | 18 | ▶ | or delete $opt{errno}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 18 | my @msg = shift @text; | |||||||||||||||||||||||||||
| 51 | 18 | ▶ | length $msg[0] or $msg[0] = 'stopped'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 18 | my @stack; | |||||||||||||||||||||||||||
| 54 | 18 | foreach (@text) | |||||||||||||||||||||||||||
| 55 | 16 | ▶ | { if(m/^\s*(.*?)\s+called at (.*?) line (\d+)\s*$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 15 | { push @stack, [ $1, $2, $3 ] } | |||||||||||||||||||||||||||
| 57 | 1 | else { push @msg, $_ } | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 18 | $opt{stack} = \@stack; | |||||||||||||||||||||||||||
| 60 | 18 | ▶ | $opt{classes} = [ 'perl', (@stack ? 'confess' : 'die') ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | my $reason | ||||||||||||||||||||||||||||
| 63 | = $opt{errno} ? 'FAULT' | ||||||||||||||||||||||||||||
| 64 | : @stack ? 'PANIC' | ||||||||||||||||||||||||||||
| 65 | 18 | ▶ | : $args{on_die} || 'ERROR'; | ||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$args{"on_die"} or "ERROR"
MC/DC100%1/1
$args{"on_die"} or "ERROR"
$args{"on_die"}
Truth table100%2/2
A
A= $args{"on_die"}
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 18 | (\%opt, $reason, join("\n", @msg), 'die'); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub _exception_dbix($$) | ||||||||||||||||||||||||||||
| 72 | 5 | ▶ | { my ($exception, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_exception_dbix: called CC=11 SCAR=24.6
| |||||||||||||||||||||||||||||
| 73 | 5 | my $on_die = delete $args->{on_die}; | |||||||||||||||||||||||||||
| 74 | 5 | my %opts = %$args; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5 | my @lines = split /\n/, "$exception"; # accessor missing to get msg | |||||||||||||||||||||||||||
| 77 | 5 | my $first = shift @lines; | |||||||||||||||||||||||||||
| 78 | 5 | my ($sub, $message, $fn, $linenr) = $first =~ | |||||||||||||||||||||||||||
| 79 | m/^ (?: ([\w:]+?) \(\)\: [ ] | \{UNKNOWN\}\: [ ] )? | ||||||||||||||||||||||||||||
| 80 | (.*?) | ||||||||||||||||||||||||||||
| 81 | \s+ at [ ] (.+) [ ] line [ ] ([0-9]+)\.? | ||||||||||||||||||||||||||||
| 82 | $/x; | ||||||||||||||||||||||||||||
| 83 | 5 | ▶ | my $pkg = defined $sub && $sub =~ s/^([\w:]+)\:\:// ? $1 : $0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $sub and $sub =~ s/^([\w:]+)\:\://
MC/DC50%1/2
defined $sub and $sub =~ s/^([\w:]+)\:\://
defined $sub
$sub =~ s/^([\w:]+)\:\://
Truth table66%2/3
A and B
A= defined $subB= $sub =~ s/^([\w:]+)\:\://
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 5 | ▶ | $opts{location} ||= [ $pkg, $fn, $linenr, $sub ]; | ||||||||||||||||||||||||||
|
Condition50%1/2
$opts{"location"} ||= [$pkg, $fn, $linenr, $sub]
MC/DC0%0/1
$opts{"location"} ||= [$pkg, $fn, $linenr, $sub]
$opts{"location"}
Truth table50%1/2
A
A= $opts{"location"}
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 5 | my @stack; | |||||||||||||||||||||||||||
| 88 | 5 | foreach (@lines) | |||||||||||||||||||||||||||
| 89 | 2 | ▶ | { my ($func, $fn, $linenr) = /^\s+(.*?)\(\)\s+called at (.*?) line ([0-9]+)$/ or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 2 | push @stack, [ $func, $fn, $linenr ]; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 5 | ▶ | $opts{stack} ||= \@stack if @stack; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$opts{"stack"} ||= \@stack
MC/DC0%0/1
$opts{"stack"} ||= \@stack
$opts{"stack"}
Truth table50%1/2
A
A= $opts{"stack"}
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | my $reason | ||||||||||||||||||||||||||||
| 95 | 5 | ▶ | = $opts{errno} ? 'FAULT' | ||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$on_die or "ERROR"
MC/DC0%0/1
$on_die or "ERROR"
$on_die
Truth table50%1/2
A
A= $on_die
| |||||||||||||||||||||||||||||
| 96 | : @stack ? 'PANIC' | ||||||||||||||||||||||||||||
| 97 | : $on_die || 'ERROR'; | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 5 | (\%opts, $reason, $message, 'exception, dbix'); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 17 | my %_libxml_errno2reason = (1 => 'WARNING', 2 => 'MISTAKE', 3 => 'ERROR'); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub _exception_libxml($$) | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | { my ($exc, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_exception_libxml: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 106 | 0 | my $on_die = delete $args->{on_die}; | |||||||||||||||||||||||||||
| 107 | 0 | my %opts = %$args; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | $opts{errno} ||= $exc->code + 13000; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opts{"errno"} ||= $exc->code + 13000
MC/DC0%0/2
$opts{"errno"} ||= $exc->code + 13000
$opts{"errno"}
$exc->code + 13000
Truth table0%0/3
A ||= B
A= $opts{"errno"}B= $exc->code + 13000
| |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $opts{location} ||= [ 'libxml', $exc->file, $exc->line, $exc->domain ]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"location"} ||= ["libxml", $exc->file, $exc->line, $exc->domain]
MC/DC0%0/1
$opts{"location"} ||= ["libxml", $exc->file, $exc->line, $exc->domain]
$opts{"location"}
Truth table0%0/2
A
A= $opts{"location"}
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $msg = $exc->message . $exc->context . "\n" | |||||||||||||||||||||||||||
| 113 | . (' ' x $exc->column) . '^' | ||||||||||||||||||||||||||||
| 114 | . ' (' . $exc->domain . ' error ' . $exc->code . ')'; | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my $reason = $_libxml_errno2reason{$exc->level} || 'PANIC'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$_libxml_errno2reason{$exc->level} || 'PANIC'
MC/DC0%0/1
$_libxml_errno2reason{$exc->level} || 'PANIC'
$_libxml_errno2reason{$exc->level}
Truth table0%0/2
A
A= $_libxml_errno2reason{$exc->level}
| |||||||||||||||||||||||||||||
| 117 | 0 | (\%opts, $reason, $msg, 'exception, libxml'); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub exception_decode($%) | ||||||||||||||||||||||||||||
| 121 | 5 | ▶ | { my ($exception, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
exception_decode: called CC=5 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 5 | my $errno = $! + 0; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 5 | ▶ | return _exception_dbix($exception, \%args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | if $exception->isa('DBIx::Class::Exception'); | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return _exception_libxml($exception, \%args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | if $exception->isa('XML::LibXML::Error'); | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | # Unsupported exception system, sane guesses | ||||||||||||||||||||||||||||
| 131 | 0 | my %opt = ( | |||||||||||||||||||||||||||
| 132 | classes => [ 'unknown exception', 'die', ref $exception ], | ||||||||||||||||||||||||||||
| 133 | errno => $errno, | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $reason = $errno ? 'FAULT' : ($args{on_die} || 'ERROR'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$args{"on_die"} or "ERROR"
MC/DC0%0/1
$args{"on_die"} or "ERROR"
$args{"on_die"}
Truth table0%0/2
A
A= $args{"on_die"}
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # hopefully stringification is overloaded | ||||||||||||||||||||||||||||
| 139 | 0 | (\%opt, $reason, "$exception", 'exception'); | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 17 | "to die or not to die, that's the question"; | |||||||||||||||||||||||||||