Bug #5851
closedException found in XdmFunctionItem.call Message=
100%
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
Updated by O'Neil Delpratt almost 2 years 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
Updated by O'Neil Delpratt almost 2 years 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);
}
Updated by Martin Honnen almost 2 years 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.
Updated by O'Neil Delpratt almost 2 years 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.
Updated by O'Neil Delpratt almost 2 years ago
- Blocked by Bug #5854: PyDocumentBuilder missing exception handling method added
Updated by Martin Honnen almost 2 years ago
Sounds great, thanks, sorry for asking perhaps a bit too impatiently while you are still working on it.
Updated by O'Neil Delpratt almost 2 years ago
- Blocked by deleted (Bug #5854: PyDocumentBuilder missing exception handling method)
Updated by O'Neil Delpratt almost 2 years ago
Bug issue marked as resolved. We now throw the exception.
Updated by O'Neil Delpratt almost 2 years ago
- Related to Bug #5781: If the stylesheet is not well-formed, compile_stylesheet silently ignores the error added
Updated by O'Neil Delpratt over 1 year 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