Robust CLI error handling

Fixes #528, fixes #524, fixes #518
Merge pull request #530 from GitbookIO/fix/cli-error-handling

Robust CLI error handling