Bug #5781
closedIf the stylesheet is not well-formed, compile_stylesheet silently ignores the error
100%
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.
Related issues
Updated by O'Neil Delpratt about 2 years ago
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.
Updated by O'Neil Delpratt almost 2 years ago
- Related to Bug #5851: Exception found in XdmFunctionItem.call Message= added
Updated by O'Neil Delpratt almost 2 years ago
- 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.
Updated by Martin Honnen almost 2 years ago
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.
Updated by O'Neil Delpratt almost 2 years ago
- Status changed from Resolved to In Progress
I will look into the issue of error codes and line numbers.
Updated by O'Neil Delpratt almost 2 years ago
- 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.
Updated by O'Neil Delpratt almost 2 years 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