Improve consistency of error handling

Ensure that all errors are handled in a consistent way and cap the buffer size
to prevent any chance of run-away buffers.
Fix indentation mistake
Merge pull request #23 from papertrail/more-consistent-error-handling

Improve consistency of error handling