MCPcopy Create free account
hub / github.com/BaseXdb/basex / addError

Method addError

basex-core/src/main/java/org/basex/query/func/unit/Unit.java:215–250  ·  view source on GitHub ↗

Adds an error element to the specified test case. @param ex exception @param testcase testcase element @param code error code (can be null)

(final QueryException ex, final FBuilder testcase, final QNm code)

Source from the content-addressed store, hash-verified

213 * @param code error code (can be {@code null})
214 */
215 private void addError(final QueryException ex, final FBuilder testcase, final QNm code) {
216 final QNm name = ex.qname();
217 if(code == null || !code.eq(name)) {
218 final FBuilder error;
219 final boolean fail = UNIT_FAIL.eq(name);
220 if(fail) {
221 failures++;
222 error = FElem.build(Q_FAILURE);
223 } else {
224 errors++;
225 error = FElem.build(Q_ERROR);
226 }
227 error.attr(Q_LINE, ex.line()).attr(Q_COLUMN, ex.column());
228 final String url = IO.get(ex.path()).url();
229 if(!file.url().equals(url)) error.attr(Q_URI, url);
230
231 if(ex instanceof final UnitException ue) {
232 // unit exception: add expected and returned values
233 error.node(element(ue.returned, Q_RETURNED, ue.count));
234 error.node(element(ue.expected, Q_EXPECTED, ue.count));
235 } else if(!fail) {
236 // exception other than failure: add type
237 error.attr(Q_TYPE, ex.qname().prefixId(QueryText.ERROR_URI));
238 }
239
240 // add info
241 final Value value = ex.value();
242 if(value != null && value.size() == 1) {
243 error.node(element((Item) value, Q_INFO, -1));
244 } else {
245 // otherwise, add error message
246 error.node(FElem.build(Q_INFO).text(ex.getLocalizedMessage()));
247 }
248 testcase.node(error);
249 }
250 }
251
252 /**
253 * Creates a new element.

Callers 1

testMethod · 0.95

Calls 15

buildMethod · 0.95
attrMethod · 0.95
getMethod · 0.95
nodeMethod · 0.95
elementMethod · 0.95
prefixIdMethod · 0.80
eqMethod · 0.65
sizeMethod · 0.65
qnameMethod · 0.45
lineMethod · 0.45
columnMethod · 0.45
urlMethod · 0.45

Tested by

no test coverage detected