Improve error handling and output

[ci skip]