encapsulates the error message construction into an function that can be passed in an option param