Refactor error message reporting using metadata.