Skip to main content
Kasyan Servetsky
Legend
September 28, 2015
Answered

Is it possible to receive an error message from “glue code”?

  • September 28, 2015
  • 1 reply
  • 449 views

Dear all,

I wrote a script that applies styles using xPath using two modes:

  • xml-rules
  • evaluate  xPath expression

For example, I want to get the first book element that is the child of the bookstore element:

/bookstore/book[last()]

This works in the “evaluate xPath expression” mode.

If no elements have been found, the script gives a warning.

But in the xml-rules mode it doesn’t work because, as far as I understand, last() isn’t supported  in xml-rules so it silently throws an error. As a result nothing happens (no warning appears) when I click the “Find” button and no matches are found.

Regards,

Kasyan

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi Kasyan,

I just dropped an eye on glue code and any catch instruction throws a cascading error till the initial code. So the error just be notified at the very first level. However, in a scriptUI environment, such an error may remains silent. My guess is that there is some bug in the ScriptUI layer that doesn't deal with errors at some point (that's my feeling, not a statement).

Have you tried a global try catch on  your main call ? Try to put some log in it and see what happens. Once again, the error should bubble to the main call according to the glue code impelmentation.

Also, you can try to run your code without passing through the UI.

FWIW,

Loic

1 reply

Loic.Aigon
Loic.AigonCorrect answer
Legend
September 28, 2015

Hi Kasyan,

I just dropped an eye on glue code and any catch instruction throws a cascading error till the initial code. So the error just be notified at the very first level. However, in a scriptUI environment, such an error may remains silent. My guess is that there is some bug in the ScriptUI layer that doesn't deal with errors at some point (that's my feeling, not a statement).

Have you tried a global try catch on  your main call ? Try to put some log in it and see what happens. Once again, the error should bubble to the main call according to the glue code impelmentation.

Also, you can try to run your code without passing through the UI.

FWIW,

Loic

Loic.Aigon
Legend
September 28, 2015

Indeed, it looks like XMLRules XPath implementation doesn't support XPath functions. Nor Position() nor Count() would work.

You may need to output the position computation like :

var getCount = function  (doc, xpath ) {

  var xf = File ( Folder.temp+"/temp.xml" );

  var x;

  doc.exportFile ( ExportFormat.XML, xf );

  xf.open('r');

  x = XML ( xf.read() );

  xf.close();

  xf.execute();

  return x.xpath ( "count("+xpath+")" );

}

var t = new test;

var count = getCount ( app.activeDocument, "./bookstore/book" )

t.xpath="/bookstore/book["+count+"]/title";

var myRuleSet = ;

HTH,

Loic