Bug #5781
closed
If the stylesheet is not well-formed, compile_stylesheet silently ignores the error
Fixed in Maintenance Release:
Description
When I was putting together the test page for the 11.99 pre-release, I had this method call:
xexec = xslt.compile_stylesheet(stylesheet_file="doc2html.xsl")
I was unaware that I'd introduced a markup error in the stylesheet and compile_stylesheet()
simply returned None
without any error message. It was only later when I attempted to parse the stylesheet as XML that the error was reported.
- Private changed from Yes to No
Due to historic reasons to do with JNI exception handling in SaxonC 11 "Exceptions and errors are captured and maintained silently in SaxonC, but can be accessed" this is via the @getErrorMessage()@ method. See the SaxonC 11 documentation section on debugging: https://www.saxonica.com/saxon-c/documentation11/index.html#!technical/debugging
Therefore I have modified your code with some error handling:
xexec = xslt.compile_stylesheet(stylesheet_file="doc2html.xsl")
if xexec is None and xslt.exception_occurred:
print(xslt.error_message)
.......
As a first cut in SaxonC 12 we have maintained the same approach. However for SaxonC 12 there is no reason to stick to this approach of handing exceptions since we have a new and better internal design to manage exceptions and report them from Java to C++, this is because in with Graalvm we are no longer using JNI.
I hope the above workaround will work for you, while I will later look at making a widespread change to how we report exceptions. Ideally we should just get the error message reported by the exception handler from Java and throw it the exception in C++, python and PHP.
- Related to Bug #5851: Exception found in XdmFunctionItem.call Message= added
- Status changed from New to Resolved
- % Done changed from 0 to 100
- Found in version set to 12.0
I have made the change to the compile_stylesheet function to throw exception. This means that the user can catch any exception thrown.
I would like to know whether the newly introduced throw exception mechanism includes error details like error code, error line, error column position as exception properties if these details are available on the Java side.
In the current API for Python only the error message and the error code are reported to Python, important details like the error line number and the error line column are not exposed.
It would be nice if the new API with exceptions raises exceptions where such details are exposed/added to the exception if available from Saxon on the Java API level. Perhaps this is all already in there but I guess it doesn't hurt to ask now before a new release.
- Status changed from Resolved to In Progress
I will look into the issue of error codes and line numbers.
- Status changed from In Progress to Resolved
The C++ API the exception class includes the properties. I have added the error code and line number to the thrown Python exception as the error message.
- 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