@@ -178,15 +178,8 @@ private XsltExecutable compileExecutable(final Options options) throws XPathExce
178
178
FnTransform .ERROR_LISTENER .clear ();
179
179
return xsltCompiler .compile (options .xsltSource ._2 ); // .compilePackage //TODO(AR) need to implement support for xslt-packages
180
180
} catch (final SaxonApiException e ) {
181
- //Generated by us, possibly in URI resolution, above - throw it directly
182
- throwOriginalXPathException (e , ErrorCodes .FOXT0003 );
183
- final Optional <TransformerException > compilerException = FnTransform .ERROR_LISTENER .getWorst ();
184
- if (compilerException .isPresent ()) {
185
- throwOriginalXPathException (compilerException .get (), ErrorCodes .FOXT0003 );
186
- throw new XPathException (this , ErrorCodes .FOXT0003 , compilerException .get ());
187
- }
188
- //Wrap any other error
189
- throw new XPathException (this , ErrorCodes .FOXT0003 , e .getMessage ());
181
+ final Optional <Exception > compilerException = FnTransform .ERROR_LISTENER .getWorst ().map (e1 -> e1 );
182
+ throw originalXPathException (compilerException .orElse (e ), ErrorCodes .FOXT0003 );
190
183
}
191
184
}
192
185
@@ -199,11 +192,11 @@ private XsltExecutable compileExecutable(final Options options) throws XPathExce
199
192
* @param defaultErrorCode use this code and its description to fill in blanks in what we finally throw
200
193
* @throws XPathException the eventual eXist exception we may throw
201
194
*/
202
- private void throwOriginalXPathException (final Throwable e , final ErrorCodes .ErrorCode defaultErrorCode ) throws XPathException {
195
+ private XPathException originalXPathException (final Throwable e , final ErrorCodes .ErrorCode defaultErrorCode ) {
203
196
Throwable cause = e ;
204
197
while (cause != null ) {
205
198
if (cause instanceof XPathException ) {
206
- throw (XPathException ) cause ;
199
+ return (XPathException ) cause ;
207
200
}
208
201
cause = cause .getCause ();
209
202
}
@@ -215,14 +208,16 @@ private void throwOriginalXPathException(final Throwable e, final ErrorCodes.Err
215
208
final StructuredQName from = xPathException .getErrorCodeQName ();
216
209
if (from != null ) {
217
210
final QName errorCodeQName = new QName (from .getLocalPart (), from .getURI (), from .getPrefix ());
218
- final ErrorCodes .ErrorCode errorCode = new ErrorCodes .ErrorCode (errorCodeQName , defaultErrorCode . getDescription ());
219
- throw new XPathException (errorCode , cause .getMessage ());
211
+ final ErrorCodes .ErrorCode errorCode = new ErrorCodes .ErrorCode (errorCodeQName , cause . getMessage ());
212
+ return new XPathException (errorCode , cause .getMessage ());
220
213
} else {
221
- throw new XPathException (this , defaultErrorCode , cause .getMessage ());
214
+ return new XPathException (this , defaultErrorCode , cause .getMessage ());
222
215
}
223
216
}
224
217
cause = cause .getCause ();
225
218
}
219
+
220
+ return new XPathException (this , defaultErrorCode , e .getMessage ());
226
221
}
227
222
228
223
/**
@@ -339,16 +334,8 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
339
334
options , sourceNode , delivery , xslt30Transformer , resultDocuments );
340
335
return invocation .invoke ();
341
336
342
- } catch (final SaxonApiException e ) {
343
- if (e .getErrorCode () != null ) {
344
- final QName errorQn = QName .fromJavaQName (e .getErrorCode ().getStructuredQName ().toJaxpQName ());
345
- throw new XPathException (this , new ErrorCodes .ErrorCode (errorQn , e .getMessage ()), e .getMessage ());
346
- } else {
347
- throwOriginalXPathException (e , ErrorCodes .FOXT0003 );
348
- throw new XPathException (this , ErrorCodes .FOXT0003 , e .getMessage ());
349
- }
350
- } catch (final UncheckedXPathException e ) {
351
- throw new XPathException (this , ErrorCodes .FOXT0003 , e .getMessage ());
337
+ } catch (final SaxonApiException | UncheckedXPathException e ) {
338
+ throw originalXPathException (e , ErrorCodes .FOXT0003 );
352
339
}
353
340
354
341
} else {
0 commit comments