Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct error-detection for all Perl scripts #43

Open
2 tasks done
vinjana opened this issue Oct 18, 2024 · 0 comments
Open
2 tasks done

Correct error-detection for all Perl scripts #43

vinjana opened this issue Oct 18, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@vinjana
Copy link

vinjana commented Oct 18, 2024

Have you checked the docs?

Description of the bug

I/O operations like open or <> are not automatically checked for errors in Perl (compare Python, where exceptions are thrown). Instead for instance the <FH> operator returns undef if the file's end is reached or if there is an error on the stream (e.g. broken pipe).

Consequently, all usages of such function/operators in Perl need to explicitly guarded to ensure no I/O error happened.

This error can result in undetected partial processing of inputs files, in particular in less stable runtime environments and with a probability approach one when scaling out.

In the code it seems open is usually guarded (or die), but the <FH> operator is almost never guarded. Also read or write operations need to be guarded and possibly (unsure) also print FH ... should be guarded.

An example of correct(er) error handling:

my $line = readline(STDIN)
   || die "Couldn't read header from standard input: $!";

while (! eof(STDIN)) {
   my $line = readline(STDIN);
   if (! defined $line) {
     die "Couldn't read from standard input: $!";
   }
   doSomethingWith($line);
}

Command used and terminal output

None. Problem occurs sporadically.

Relevant files

Probably all Perl scripts lib/*.pl. All should be checked.

System information

This is valid for all versions of Perl and independent of all the other possible system information.

@vinjana vinjana added the bug Something isn't working label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant