exit with an error code in cli mode and re-format error message

Changes:

* in cli mode, `exit(1)` exit with error code. `exit('message');` exit program normally
* re-format error message in cli mode.
* typos, strip trailing spaces