From 5cba9f6dfc98977249a78bf8bbc4fbdd3f130220 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 12 Apr 2022 22:02:35 +0900 Subject: [PATCH 1/2] fix(workaround): RangeError: Invalid string length - refs: https://github.com/hexojs/hexo/issues/4922 --- lib/database.js | 11 +++++++++++ package.json | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/database.js b/lib/database.js index 4ab5265b..23cb54d0 100644 --- a/lib/database.js +++ b/lib/database.js @@ -10,6 +10,7 @@ const WarehouseError = require('./error'); const pkg = require('../package.json'); const { open } = fs.promises; const pipeline = Promise.promisify(require('stream').pipeline); +const log = require('hexo-log')(); let _writev; @@ -53,6 +54,16 @@ async function exportAsync(database, path) { // End models await handle.write('}}'); + } catch(e) { + log.error(e); + if (e instanceof RangeError && e.message.includes("Invalid string length")) { + // NOTE: Currently, we can't deal with anything about this issue. + // If do not `catch` the exception after the process will not work (e.g: `after_generate` filter.) + // A side-effect of this workaround is the `db.json` will not generate. + log.warn("see: https://github.com/nodejs/node/issues/35973"); + } else { + throw e; + } } finally { await handle.close(); } diff --git a/package.json b/package.json index a10bac86..de346fa3 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,12 @@ "author": "Tommy Chen (http://zespia.tw)", "license": "MIT", "dependencies": { - "JSONStream": "^1.0.7", "bluebird": "^3.2.2", "cuid": "^2.1.4", "graceful-fs": "^4.1.3", + "hexo-log": "^3.0.0", "is-plain-object": "^5.0.0", + "JSONStream": "^1.0.7", "rfdc": "^1.1.4" }, "devDependencies": { From 09b2b4fe41f4aabd6ce1b4fa81ee6b6858f3f341 Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 12 Apr 2022 22:11:47 +0900 Subject: [PATCH 2/2] fix lint --- lib/database.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/database.js b/lib/database.js index 23cb54d0..f17b7d45 100644 --- a/lib/database.js +++ b/lib/database.js @@ -54,13 +54,13 @@ async function exportAsync(database, path) { // End models await handle.write('}}'); - } catch(e) { + } catch (e) { log.error(e); - if (e instanceof RangeError && e.message.includes("Invalid string length")) { + if (e instanceof RangeError && e.message.includes('Invalid string length')) { // NOTE: Currently, we can't deal with anything about this issue. // If do not `catch` the exception after the process will not work (e.g: `after_generate` filter.) // A side-effect of this workaround is the `db.json` will not generate. - log.warn("see: https://github.com/nodejs/node/issues/35973"); + log.warn('see: https://github.com/nodejs/node/issues/35973'); } else { throw e; }