How to test readline errors (or read errors for that matter) - Perl

This is a discussion on How to test readline errors (or read errors for that matter) - Perl ; Any suggestions for how to create a test which checks if my readline error handling is working properly? How can I get readline (or read for that matter) to fail after open succeeds? -- John Wiersba...

+ Reply to Thread
Results 1 to 4 of 4

How to test readline errors (or read errors for that matter)

  1. Default How to test readline errors (or read errors for that matter)

    Any suggestions for how to create a test which checks if my readline
    error handling is working properly? How can I get readline (or read
    for that matter) to fail after open succeeds?

    -- John Wiersba

  2. Default Re: How to test readline errors (or read errors for that matter)

    jrw32982@yahoo.com wrote:
    > Any suggestions for how to create a test which checks if my readline
    > error handling is working properly? How can I get readline (or read
    > for that matter) to fail after open succeeds?


    perldoc -f readline

    [ snip ]

    If readline encounters an operating system error, $! will be set
    with the corresponding error message. It can be helpful to check $!
    when you are reading from filehandles you don’t trust, such as a tty
    or a socket. The following example uses the operator form of
    "readline", and takes the necessary steps to ensure that "readline"
    was successful.

    for (; {
    undef $!;
    unless (defined( $line = <> )) {
    die $! if $!;
    last; # reached EOF
    }
    # ...
    }


    As for read(), it returns undef on error so:

    defined( read FILEHANDLE, $buffer, $size ) or die "read error: $!";



    John
    --
    Perl isn't a toolbox, but a small machine shop where you can special-order
    certain sorts of tools at low cost and in short order. -- Larry Wall

  3. Default Re: How to test readline errors (or read errors for that matter)


    John W. Krahn wrote:
    > ...snip...


    I've seen the doc -- but how can I create a test which actually
    generates a read or readline error so that I can test if my error
    handling works properly?

  4. Default Re: How to test readline errors (or read errors for that matter)

    jrw32982@yahoo.com wrote:
    > John W. Krahn wrote:
    >>...snip...

    >
    > I've seen the doc -- but how can I create a test which actually
    > generates a read or readline error so that I can test if my error
    > handling works properly?


    According to the read(2) man page:

    ERRORS
    EAGAIN Non-blocking I/O has been selected using O_NONBLOCK and no data
    was immediately available for reading.

    EBADF fd is not a valid file descriptor or is not open for reading.

    EFAULT buf is outside your accessible address space.

    EINTR The call was interrupted by a signal before any data was read.

    EINVAL fd is attached to an object which is unsuitable for reading.

    EIO I/O error. This will happen for example when the process is in a
    background process group, tries to read from its controlling
    tty, and either it is ignoring or blocking SIGTTIN or its
    process group is orphaned. It may also occur when there is a
    low-level I/O error while reading from a disk or tape.

    EISDIR fd refers to a directory.

    Other errors may occur, depending on the object connected to fd.
    POSIX allows a read that is interrupted after reading some data to
    return -1 (with errno set to EINTR) or to return the number of bytes
    already read.


    So try one of those.


    John
    --
    Perl isn't a toolbox, but a small machine shop where you can special-order
    certain sorts of tools at low cost and in short order. -- Larry Wall

+ Reply to Thread

Similar Threads

  1. Replies: 1
    Last Post: 01-08-2007, 01:24 PM
  2. Best way to handle readline errors?
    By Application Development in forum Perl
    Replies: 0
    Last Post: 11-09-2006, 03:11 PM
  3. Replies: 4
    Last Post: 11-06-2006, 01:28 PM
  4. Obsolete Errors and Deprecated Errors using Dotnet Framework 2.0
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 06-20-2006, 10:58 AM
  5. Obsolete Errors and Deprecated Errors using Dotnet Framework 2.0
    By Application Development in forum DOTNET
    Replies: 0
    Last Post: 06-07-2006, 06:48 AM