From 8bec82f5704bea1c043bcd99aa2b2da9fa256944 Mon Sep 17 00:00:00 2001 From: brandon-fry Date: Fri, 9 Oct 2020 14:49:28 -0500 Subject: [PATCH] Fix undefined fileName in getFileName When attempting to find the file name of the caller, getFileName grabs a stack trace and attempts to walk up it to find the first file name that is not the bindings.js file. For some reason, in my environment, the bindings.js file name is 'undefined' (see output below). In this case 'undefined' !== __filename and the for loop is stopped, leaving fileName undefined and causing an error when indexOf is invoked on fileName. To fix, an additional check for undefined fileName is added in the loop. fileName: undefined function: getFileName fileName: undefined function: bindings fileName: undefined function: eval fileName: /projects/node-crfpp/node-crfpp-bundle.js function: ./node-crfpp.js --- bindings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings.js b/bindings.js index 226b37f..67df040 100644 --- a/bindings.js +++ b/bindings.js @@ -155,7 +155,7 @@ exports.getFileName = function getFileName(calling_file) { Error.prepareStackTrace = function(e, st) { for (var i = 0, l = st.length; i < l; i++) { fileName = st[i].getFileName(); - if (fileName !== __filename) { + if (fileName && fileName !== __filename) { if (calling_file) { if (fileName !== calling_file) { return;