From 477db9106acb1852a85bfb954201169f61466a55 Mon Sep 17 00:00:00 2001 From: vamsi Date: Thu, 26 Mar 2026 16:58:57 +0530 Subject: [PATCH] Fix view server crash when map/reduce function throws null When a map or reduce function throws null or undefined, the JavaScript view server's error handlers crash while attempting to stringify or access properties on the null exception. This patch adds safe null checks to these critical property accesses, allowing the view server to correctly log the exception and proceed without crashing the entire OS process. --- share/server/util.js | 1 + share/server/views.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/share/server/util.js b/share/server/util.js index 80abc3332cf..6deadada154 100644 --- a/share/server/util.js +++ b/share/server/util.js @@ -120,6 +120,7 @@ var Couch = { }; function errstr(e) { + if (e == null) return String(e); // toSource() is a Spidermonkey "special" return (e.toSource ? e.toSource() : e.toString()); }; diff --git a/share/server/views.js b/share/server/views.js index d414436bd95..19a6a8928db 100644 --- a/share/server/views.js +++ b/share/server/views.js @@ -70,11 +70,11 @@ var Views = (function() { // JavaScript process. If you need to destroy the JavaScript // process, throw the error form matched by the block below. throw(["error", "map_runtime_error", "function raised 'fatal_error'"]); - } else if (err[0] == "fatal") { + } else if (err && err[0] == "fatal") { // Throwing errors of the form ["fatal","error_key","reason"] // will kill the OS process. This is not normally what you want. throw(err); - } else if (err.name == "InternalError") { + } else if (err && err.name == "InternalError") { throw(["fatal", err.name, err.message]); } var message = "function raised exception " + errstr(err);