Skip to content

Commit

Permalink
Fix critique
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuelsmann committed Sep 30, 2023
1 parent 2c3e35f commit 5a9ebf5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/LedgerSMB/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ sub get_info {

if ($have_version_column) {
# Legacy SL and LSMB
$self->logger->trace( "Legacy SL or LSMB database" );
$self->logger->trace( 'Legacy SL or LSMB database' );
$sth = $dbh->prepare(
'SELECT version FROM defaults'
);
Expand Down Expand Up @@ -378,7 +378,7 @@ sub get_info {
$sth = $dbh->prepare('SELECT fldvalue FROM defaults WHERE fldname = ?');
$sth->execute('version');
if (my $ref = $sth->fetchrow_hashref('NAME_lc')){
$self->logger->trace( "SL" );
$self->logger->trace( 'SL' );
$retval->{appname} = 'sql-ledger';
$retval->{full_version} = $ref->{fldvalue};
$retval->{version} = $ref->{fldvalue};
Expand Down
4 changes: 2 additions & 2 deletions lib/LedgerSMB/Database/Loadorder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ sub scripts {
map { $self->_limit_by_tag($_) }
<$fh>;
close $fh or die "Cannot open file $self->{_path}";
$log->trace( "Considering schema patches: " . join(', ',
map { $_->path } @scripts) );
$log->tracef( 'Considering schema patches: %s',
join(', ', map { $_->path } @scripts) );
$self->{_scripts} = \@scripts;
return @scripts;
}
Expand Down
45 changes: 37 additions & 8 deletions lib/LedgerSMB/Scripts/setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use Digest::MD5 qw(md5_hex);
use Encode;
use File::Spec;
use HTML::Escape;
use HTTP::Status qw( HTTP_OK HTTP_UNAUTHORIZED );
use HTTP::Status qw( HTTP_OK HTTP_INTERNAL_SERVER_ERROR HTTP_UNAUTHORIZED );
use Log::Any;
use MIME::Base64;
use Scope::Guard;
Expand Down Expand Up @@ -725,14 +725,43 @@ sub _process_and_run_upgrade_script {
}
catch ($e) {
my $error_text = escape_html( $e );
local $/;
open my $out, '<:encoding(UTF-8)', $upgrade->logfiles->{out};
open my $err, '<:encoding(UTF-8)', $upgrade->logfiles->{err};
my $stdout = escape_html( <$out> );
my $stderr = escape_html( <$err> );
return [ 500,
local $/ = undef;
my $stdout = '';
if ( open( my $out, '<:encoding(UTF-8)', $upgrade->logfiles->{out} ) ) {
$stdout = escape_html( <$out> );
}
else {
$logger->warn(
"Unable to open psql upgrade script STDOUT logfile: $!"
);
}

my $stderr = '';
if ( open( my $err, '<:encoding(UTF-8)', $upgrade->logfiles->{err} ) ) {
$stderr = escape_html( <$err> );
}
else {
$logger->warn(
"Unable to open psql upgrade script STDERR logfile: $!"
);
}

return [ HTTP_INTERNAL_SERVER_ERROR,
[ 'Content-Type' => 'text/html; charset=UTF-8' ],
[ "<html><body><h1>Error!</h1><p><b>$error_text</b></p><h3>STDERR</h3><pre style='max-height:30em;overflow:scroll'>$stderr</pre><h3>STDOUT</h3><pre style='max-height:30em;overflow:scroll'>$stdout</pre></body></html>" ] ];
[ <<~EMBEDDED_HTML ] ];
<html>
<body>
<h1>Error!</h1>
<p><b>$error_text</b></p>
<h3>STDERR</h3>
<pre style="max-height:30em;overflow:scroll">$stderr</pre>
<h3>STDOUT</h3>
<pre style="max-height:30em;overflow:scroll">$stdout</pre>
</body>
</html>
EMBEDDED_HTML
};

return;
Expand Down
2 changes: 1 addition & 1 deletion xt/01.1-critic.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sub test_files {
Perl::Critic::Violation::set_format( 'S%s %p %f: %l\n');

for my $file (@$files) {
tests critique => { async => (! $ENV{COVERAGE}) }, sub {
tests "critique for $file" => { async => (! $ENV{COVERAGE}) }, sub {
my @findings = map { "$_" } $critic->critique($file);

ok(scalar(@findings) == 0, "Critique for $file");
Expand Down

0 comments on commit 5a9ebf5

Please sign in to comment.