Ensure that the errorWrapper is closed when a new document is opened (issue 4625)

Fixes #4625.