Add missing specs and docs and refactor error message creation