XPath has an error function, https://www.w3.org/TR/xpath-functions-31/#func-error which stops processing, which isn't wanted when it's just a warning. ("this thing has problems; on to the next thing" shouldn't stop processing.)
This leaves me thinking I've missed something -- how should I have a query give a warning? I'm not finding something BaseX specific; I'm fairly sure neither error() nor trace() are correct.