You appear to have a ‘Link’ in a note that is pointing to something that has been deleted or merged out of existence. Your search through the XML to find handle, (and find the link) is probably failing because you have a leading space in the search string ’ '. You may want to just search for the last 5-6 characters of the handle, making sure the find is not requiring a whole word, as handles in the XML are always preceded by the ‘_’ character.
Check and Repair doesn’t currently find this sort of problem.
We are aware of this issue and have made some fixes https://github.com/gramps-project/gramps/pull/1093/files in the upcoming 5.2 release. Unfortunately I think the changes are a bit much to add to the current code by the typical user.