[Pkg-javascript-commits] [node-jsonstream] 191/214: catch error when stringifying a chunk and end stream when such error occurs

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 1 12:58:59 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-jsonstream.

commit f61bc1958f2552e7bebb5ddab0baebc5e8318528
Author: Vojta Tranta <vojta.tranta at gmail.com>
Date:   Wed Jun 29 16:03:33 2016 +0200

    catch error when stringifying a chunk and end stream when such error occurs
---
 index.js | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 1ed71a4..1e0a4f9 100755
--- a/index.js
+++ b/index.js
@@ -111,7 +111,7 @@ exports.parse = function (path, map) {
       }
     }
   }
-  
+
   parser.onError = function (err) {
     if(err.message.indexOf("at position") > -1)
       err.message = "Invalid JSON (" + err.message + ")";
@@ -155,7 +155,12 @@ exports.stringify = function (op, sep, cl, indent) {
     , anyData = false
   stream = through(function (data) {
     anyData = true
-    var json = JSON.stringify(data, null, indent)
+    try {
+      var json = JSON.stringify(data, null, indent)
+    } catch (err) {
+      stream.emit('error', err)
+      return stream.end()
+    }
     if(first) { first = false ; stream.queue(op + json)}
     else stream.queue(sep + json)
   },

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-jsonstream.git



More information about the Pkg-javascript-commits mailing list