From 021242a7bfb54808b0736855cb1ca06c9b66f9ef Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Sat, 3 Feb 2018 15:58:14 +0100 Subject: [PATCH] fix: use json-stringify-safe on unknown errors --- lib/workers/repository/error.js | 18 ++---------------- package.json | 1 + yarn.lock | 2 +- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/lib/workers/repository/error.js b/lib/workers/repository/error.js index af3cc63735..c75cba052a 100644 --- a/lib/workers/repository/error.js +++ b/lib/workers/repository/error.js @@ -1,3 +1,4 @@ +const stringify = require('json-stringify-safe'); const { raiseConfigWarningIssue } = require('./error-config'); module.exports = { @@ -47,24 +48,9 @@ async function handleError(config, err) { // Swallow this error so that other repositories can be processed logger.error( { err }, - `Repository has unknown error:\n${stringifyError(err, null, ' ')}` + `Repository has unknown error:\n${stringify(err, null, 2)}` ); // delete branchList to avoid cleaning up branches delete config.branchList; // eslint-disable-line no-param-reassign return 'unknown-error'; } - -function stringifyError(err, filter, space) { - let stringifiedError = ''; - try { - const plainObject = {}; - Object.getOwnPropertyNames(err).forEach(key => { - plainObject[key] = err[key]; - }); - stringifiedError = JSON.stringify(plainObject, filter, space); - } catch (err2) { - // istanbul ignore next - logger.warn({ err2 }, 'Error stringifying unknown error'); - } - return stringifiedError; -} diff --git a/package.json b/package.json index 89cc1cec20..54d1da8b02 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "js-yaml": "3.10.0", "json-dup-key-validator": "1.0.2", "json-stringify-pretty-compact": "1.1.0", + "json-stringify-safe": "5.0.1", "later": "1.2.0", "lodash": "4.17.4", "minimatch": "3.0.4", diff --git a/yarn.lock b/yarn.lock index e3b6747504..b6fe2fd165 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4034,7 +4034,7 @@ json-stringify-pretty-compact@1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/json-stringify-pretty-compact/-/json-stringify-pretty-compact-1.1.0.tgz#4fa5b898f61a287d64828691baa822a41f3ad5ab" -json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1: +json-stringify-safe@5.0.1, json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" -- GitLab