Skip to content

Commit

Permalink
build the correct error
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Feb 3, 2025
1 parent dedf6ff commit 20a7f75
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ else if (JavaScriptEngine.isUndefined(position)) {
ex.code));
}
}
throw JavaScriptEngine.syntaxError(e.getMessage());
throw JavaScriptEngine.asJavaScriptException(
getWindow(),
new org.htmlunit.javascript.host.dom.DOMException(
e.getMessage(),
org.htmlunit.javascript.host.dom.DOMException.SYNTAX_ERR));
}
}

Expand Down
23 changes: 17 additions & 6 deletions src/main/java/org/htmlunit/javascript/host/dom/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,11 @@ else if (resolver instanceof PrefixResolver) {
return xPathResult;
}
catch (final Exception e) {
throw JavaScriptEngine.syntaxError("Failed to execute 'evaluate': " + e.getMessage());
throw JavaScriptEngine.asJavaScriptException(
getWindow(),
new org.htmlunit.javascript.host.dom.DOMException(
"Failed to execute 'evaluate': " + e.getMessage(),
org.htmlunit.javascript.host.dom.DOMException.SYNTAX_ERR));
}
}

Expand Down Expand Up @@ -982,9 +986,12 @@ public Node querySelector(final String selectors) {
return null;
}
catch (final CSSException e) {
throw JavaScriptEngine.syntaxError(
"An invalid or illegal selector was specified (selector: '"
+ selectors + "' error: " + e.getMessage() + ").");
throw JavaScriptEngine.asJavaScriptException(
getWindow(),
new org.htmlunit.javascript.host.dom.DOMException(
"An invalid or illegal selector was specified (selector: '"
+ selectors + "' error: " + e.getMessage() + ").",
org.htmlunit.javascript.host.dom.DOMException.SYNTAX_ERR));
}
}

Expand All @@ -1001,8 +1008,12 @@ public NodeList querySelectorAll(final String selectors) {
return NodeList.staticNodeList(this, getDomNodeOrDie().querySelectorAll(selectors));
}
catch (final CSSException e) {
throw JavaScriptEngine.syntaxError("An invalid or illegal selector was specified (selector: '"
+ selectors + "' error: " + e.getMessage() + ").");
throw JavaScriptEngine.asJavaScriptException(
getWindow(),
new org.htmlunit.javascript.host.dom.DOMException(
"An invalid or illegal selector was specified (selector: '"
+ selectors + "' error: " + e.getMessage() + ").",
org.htmlunit.javascript.host.dom.DOMException.SYNTAX_ERR));
}
}

Expand Down

0 comments on commit 20a7f75

Please sign in to comment.