Project

Profile

Help

Bug #5851

closed

Exception found in XdmFunctionItem.call Message=

Added by O'Neil Delpratt about 1 year ago. Updated 12 months ago.

Status:
Closed
Priority:
Normal
Category:
C++ API
Start date:
2023-01-23
Due date:
% Done:

100%

Estimated time:
Found in version:
12.0
Fixed in version:
12.1
Platforms:

Description

Bug issue reported by user here: https://saxonica.plan.io/boards/4/topics/9235

For the following python code:

from saxonche import *

with PySaxonProcessor(license=True) as proc:
    print(proc.version)
    parse_ietf_date = PyXdmFunctionItem().get_system_function(proc, "{http://www.w3.org/2005/xpath-functions}parse-ietf-date", 1)
    for date in ["Wed, 06 Jun 1994 07:29:35 GMT", "We, 06 Jun 1994 07:29:35 GMT"]:
        date_xdm_string = proc.make_string_value(date)
        result = parse_ietf_date.call(proc, [date_xdm_string])
        if proc.exception_occurred:
            print(proc.error_message)
        else:
            print(result)

We get the following output:

SaxonC-HE 12.0 from Saxonica
1994-06-06T07:29:35Z
None
Exception found in XdmFunctionItem.call Message= Invalid IETF date value We, 06 Jun 1994 07:29:35 GMT (String expected to begin with month name or day name (or day number))

The message "Exception found in ...." is actually a std::cerr print message in the C++ code. It is present because we are not throwing the exception from the Java code as in the same way as for Processor objects.


Related issues

Related to SaxonC - Bug #5781: If the stylesheet is not well-formed, compile_stylesheet silently ignores the errorClosedO'Neil Delpratt2022-12-22

Actions
Actions #1

Updated by O'Neil Delpratt about 1 year ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Bug fixed by throwing the exception which user can catch in the Python, C++ and PHP

Actions #2

Updated by O'Neil Delpratt about 1 year ago

Bug fix available in the next maintenance release.

The change made was in the C++ file: XdmFunctionItem.cpp. The workaround would be to compile and build the Python wheel yourself from the source files:

    XdmValue * XdmFunctionItem::call(SaxonProcessor * processor, XdmValue ** arguments, int argument_length) {
          if((argument_length > 0 && arguments == nullptr) || processor == nullptr) {
              SaxonApiException * exception = new SaxonApiException("Error in XdmFunctionItem.call.  nullptr arguments found.");
              throw exception;
          }

          int64_t argumentJArrayRef = SaxonProcessor::createJArray(arguments, argument_length);
          if(argumentJArrayRef == -1 && argument_length > 0) {
            SaxonApiException * exception = new SaxonApiException("Error in XdmFunctionItem.call when converting arguments -   nullptr arguments found.\"");
            throw exception;
          }
           int64_t results = j_xdmFunctionItem_call(SaxonProcessor::sxn_environ->thread, (void *)processor->procRef, (void *)value, (argumentJArrayRef == -1 ? (void *) nullptr: (void *)argumentJArrayRef));
           if(argumentJArrayRef != -1) {
               j_handles_destroy(SaxonProcessor::sxn_environ->thread, (void *)argumentJArrayRef);
               argumentJArrayRef = -1;
           }
           if(results == -2) {
               SaxonApiException * exception = new SaxonApiException();
               throw exception;
           }
        return getXdmValueSubClass(results);

    }
Actions #3

Updated by Martin Honnen about 1 year ago

O'Neil Delpratt wrote in #note-2:

Bug fix available in the next maintenance release.

The change made was in the C++ file: XdmFunctionItem.cpp. The workaround would be to compile and build the Python wheel yourself from the source files:

    XdmValue * XdmFunctionItem::call(SaxonProcessor * processor, XdmValue ** arguments, int argument_length) {
          if((argument_length > 0 && arguments == nullptr) || processor == nullptr) {
              SaxonApiException * exception = new SaxonApiException("Error in XdmFunctionItem.call.  nullptr arguments found.");
              throw exception;
          }

          int64_t argumentJArrayRef = SaxonProcessor::createJArray(arguments, argument_length);
          if(argumentJArrayRef == -1 && argument_length > 0) {
            SaxonApiException * exception = new SaxonApiException("Error in XdmFunctionItem.call when converting arguments -   nullptr arguments found.\"");
            throw exception;
          }
           int64_t results = j_xdmFunctionItem_call(SaxonProcessor::sxn_environ->thread, (void *)processor->procRef, (void *)value, (argumentJArrayRef == -1 ? (void *) nullptr: (void *)argumentJArrayRef));
           if(argumentJArrayRef != -1) {
               j_handles_destroy(SaxonProcessor::sxn_environ->thread, (void *)argumentJArrayRef);
               argumentJArrayRef = -1;
           }
           if(results == -2) {
               SaxonApiException * exception = new SaxonApiException();
               throw exception;
           }
        return getXdmValueSubClass(results);

    }

Is there no error message set if the function call fails? Is that not possible or did you overlook that?

I think I have a build from Norms buildwheels that might contain the above fix as code like

from saxonche import *

with PySaxonProcessor(license=True) as proc:
    print(proc.version)

    parse_ietf_date = PyXdmFunctionItem().get_system_function(proc, "{http://www.w3.org/2005/xpath-functions}parse-ietf-date", 1)

    for date in ["Wed, 06 Jun 1994 07:29:35 GMT", "We, 06 Jun 1994 07:29:35 GMT"]:
        date_xdm_string = proc.make_string_value(date)
        try:
            result = parse_ietf_date.call(proc, [date_xdm_string])
            print(result)
            proc.exception_clear()
        except Exception as ex:
            print('Exception parsing date:', date_xdm_string, ex, proc.error_message)
            proc.exception_clear()

gives me exception handling but unfortunately without any exception message:

SaxonC-HE 12.0 from Saxonica
1994-06-06T07:29:35Z
Exception parsing date: We, 06 Jun 1994 07:29:35 GMT Unknown exception None

Isn't it possible to pass on the exception message (e.g. "invalid IETF date value We, 06 Jun 1994 07:29:35 GMT...") the Java code raises from Java to C++ to Python?

That would make the API much more useful and meaningful.

Actions #4

Updated by O'Neil Delpratt about 1 year ago

Martin Honnen wrote in #note-3: ``

Is there no error message set if the function call fails? Is that not possible or did you overlook that?

If you look at the SaxonApiException class you will see some more insight to what is going one: In the case of no error message being passed as argument initiates a callback to the Java code to get the error message.

I think I have a build from Norms buildwheels that might contain the above fix as code like

gives me exception handling but unfortunately without any exception message:

SaxonC-HE 12.0 from Saxonica
1994-06-06T07:29:35Z
Exception parsing date: We, 06 Jun 1994 07:29:35 GMT Unknown exception None

Isn't it possible to pass on the exception message (e.g. "invalid IETF date value We, 06 Jun 1994 07:29:35 GMT...") the Java code raises from Java to C++ to Python?

That would make the API much more useful and meaningful.

This bug is actually dependant on the bug issue: #5854 (I will mark this dependency accordingly). We have redesigned the code to throw the exception instead of using our own exception callback methods. This redesign is not yet committed as I am still working on it.

However for your python script in comment #3 I am now getting the following output:

SaxonC-EE 12.0 from Saxonica
1994-06-06T07:29:35Z
Exception parsing date: We, 06 Jun 1994 07:29:35 GMT Invalid IETF date value We, 06 Jun 1994 07:29:35 GMT (String expected to begin with month name or day name (or day number)) None

This is what you would expect and is more useful.

Actions #5

Updated by O'Neil Delpratt about 1 year ago

  • Blocked by Bug #5854: PyDocumentBuilder missing exception handling method added
Actions #6

Updated by Martin Honnen about 1 year ago

Sounds great, thanks, sorry for asking perhaps a bit too impatiently while you are still working on it.

Actions #7

Updated by O'Neil Delpratt about 1 year ago

  • Blocked by deleted (Bug #5854: PyDocumentBuilder missing exception handling method)
Actions #8

Updated by O'Neil Delpratt about 1 year ago

Bug issue marked as resolved. We now throw the exception.

Actions #9

Updated by O'Neil Delpratt about 1 year ago

  • Related to Bug #5781: If the stylesheet is not well-formed, compile_stylesheet silently ignores the error added
Actions #10

Updated by O'Neil Delpratt 12 months ago

  • Status changed from Resolved to Closed
  • Fixed in version set to 12.1

Bug fixed applied in the SaxonC 12.1 maintenance release.

Please register to edit this issue

Also available in: Atom PDF