[Console] fix and refactor exit code handling