fix: use errstr() instead of toSource() in nouveau handleIndexError for QuickJS compatibility#5951
Open
vamsi2246 wants to merge 2 commits intoapache:mainfrom
Open
fix: use errstr() instead of toSource() in nouveau handleIndexError for QuickJS compatibility#5951vamsi2246 wants to merge 2 commits intoapache:mainfrom
vamsi2246 wants to merge 2 commits intoapache:mainfrom
Conversation
Replace SpiderMonkey-specific err.toSource() with the cross-engine errstr() helper in nouveau.js handleIndexError(). The errstr() function (defined in util.js) safely checks for toSource availability before calling it, falling back to toString(). This is consistent with the identical pattern used in dreyfus.js handleIndexError(). Without this fix, any non-fatal error thrown by a Nouveau index function on QuickJS causes the error handler itself to crash with a TypeError, preventing graceful error logging and document skipping.
Contributor
|
Thanks for your contribution, @vamsi2246 Please fill out the PR template. Coincidentally, there is a parallel discussion in another PR #5943 (review) about how Wonder if we could cover this case by a test. It should be enough just to copy and paste a test from nouveau Elixir test and make it throw, like so: test "index function throws", context do
db_name = context[:db_name]
create_search_docs(db_name)
ddoc = %{
nouveau: %{
bar: %{
default_analyzer: "standard",
index: """
function (doc) {
throw(new Error("some error"));
index("string", "foo", doc.foo, {store: true});
}
"""
}
}
}
create_ddoc(db_name, ddoc)
url = "/#{db_name}/_design/foo/_nouveau/bar"
resp = Couch.post(url, body: %{q: "foo:bar", include_docs: true})
assert_status_code(resp, 200)
assert resp.body["hits"] == []
endCurrently with QuickJS it should blow up with a 500 response and some ugly looking stacktrace. With this fix it should 1) return a 200 response 2) return no hits, 3) hopefully log something like "OS Process ... function raised ...". I don't think we can check for that in elixir but we hopefully will log locally. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
handleIndexError()innouveau.jscallserr.toSource(), which is a SpiderMonkey-specific method not available in QuickJS. This causes the error handler itself to crash when a Nouveau index function throws a non-fatal error on QuickJS-based deployments.This replaces
err.toSource()with the existingerrstr()helper (defined inutil.js), which safely checks fortoSourceavailability before calling it, falling back totoString(). This is consistent with the identical pattern used indreyfus.jsandviews.js.Testing recommendations
N/A - This is a trivial 1-line compatibility fix that aligns
nouveau.jswith the existing pattern indreyfus.js.