only generate error message when needed