3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-03 01:48:38 +02:00

Plugins/Plang: fix error handling

This commit is contained in:
Pragmatic Software 2020-07-26 01:02:36 -07:00
parent 747cb24392
commit a337903787
2 changed files with 21 additions and 11 deletions

2
Plang

@ -1 +1 @@
Subproject commit 41c7c3c5c801f7b440a8c90502c77777585d7274 Subproject commit 6fb7dd9fbad69819c684f6a60f88b62ca867506b

View File

@ -84,15 +84,18 @@ sub cmd_plang {
return $usage if not length $context->{arguments}; return $usage if not length $context->{arguments};
$self->{output} = ""; # collect output of the embedded Plang program $self->{output} = ""; # collect output of the embedded Plang program
my $result = $self->{plang}->interpret_string($context->{arguments});
# check to see if we need to append final result to output eval {
if (defined $result->[1]) { my $result = $self->{plang}->interpret_string($context->{arguments});
if ($result->[0] eq 'STRING') {
$self->{output} .= $self->{plang}->{interpreter}->output_string_literal($result->[1]); # check to see if we need to append final result to output
} else { if (defined $result->[1]) {
$self->{output} .= $self->{plang}->{interpreter}->output_value($result); $self->{output} .= $self->{plang}->{interpreter}->output_value($result, literal => 1);
} }
};
if ($@) {
$self->{output} .= $@;
} }
# return the output # return the output
@ -106,10 +109,17 @@ sub cmd_plangrepl {
return $usage if not length $context->{arguments}; return $usage if not length $context->{arguments};
$self->{output} = ""; # collect output of the embedded Plang program $self->{output} = ""; # collect output of the embedded Plang program
my $result = $self->{plang}->interpret_string($context->{arguments}, repl => 1);
# check to see if we need to append final result to output eval {
$self->{output} .= $self->{plang}->{interpreter}->output_value($result, repl => 1) if defined $result->[1]; my $result = $self->{plang}->interpret_string($context->{arguments}, repl => 1);
# check to see if we need to append final result to output
$self->{output} .= $self->{plang}->{interpreter}->output_value($result, repl => 1) if defined $result->[1];
};
if ($@) {
$self->{output} .= $@;
}
# return the output # return the output
return length $self->{output} ? $self->{output} : "No output."; return length $self->{output} ? $self->{output} : "No output.";