0

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?

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
Antony
  • 183
  • 8
  • 1
    If you were to catch the exception, are you expecting to be able to catch the TDE exception to skip over TDE processing, but still save the document? For your particular issue, if looks as if it expects a single value for a column and you have multiple values, so you could apply a different TDE and generate multiple rows for that column, select just one value instead of all that match, or concatenate them and produce a single string. – Mads Hansen Feb 01 '22 at 12:36
  • @MadsHansen We finally decided to modify the existing template to pickup one value instead of all matches because we don't want to lose the data in reporting and also allow the saving of record. – Antony Feb 03 '22 at 13:41

1 Answers1

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 ]