'Handle TDE errors in Marklogic Xquery

I have created templates for documents present in my ML content database without <invalid-values>ignore</invalid-values>. So, my code throws TDE-INDEX error when there is an invalid row value during create / update of the document.

TDE-INDEX: xdmp:eval("xquery version "1.0-ml"; import module namesp...", (), ****...) -- Error applying template /template.xml to document /workid.xml: TDE-EVALFAILED: Eval for Column subject_name='$subject[@code eq $subject_code]/text()' returns multiple values (only one is expected)

Now I have a requirement where I need to track this error in the ErrorLog.txt file and continue the document insertion.

From the Marklogic documents regarding TDE, I could see this can be handled in two ways.

  1. Setting <invalid-values>ignore</invalid-values> and we cannot log the error and it would continue the operation

  2. Without the option, the error would be thrown and the processing would be stopped.

Now there are two questions for which I'm looking answers for:

  1. Is it possible to catch the TDE errors using try/catch expression?

  2. Is it possible to log the TDE error and allow document insert/update operation?



Solution 1:[1]

For all of our mission critical documents using TDE, we actually first do an explicit call to validate the document against an XSD. Then we know in advance if it would error on a strict TDE template. For many items, we actually generate the TDE and schema from a DSL guaranteeing that they agree.

By doing the validate in advance, one could then use business logic to log errors and trigger the TDE index or not by some switching mechanism that works with TDE:

  • collection
  • directory
  • context

One trick we often use is to embed hints to s template or sub template in context logic. For instance, you could store a Boolean about validation success in an element or collection and use a context like /some/path[fancy condition related to node -collection or element ]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Ennis