Fix host pattern matching and enhance error detection

Fixes #8614