Improved error handling for stdin.