Fix error handling with references with text, types and definitions

If the definition was syntactically wrong type and target were ignored,
this fixes it.