Skip to content

Commit

Permalink
fix(workaround): RangeError: Invalid string length (#123)
Browse files Browse the repository at this point in the history
* fix(workaround): RangeError: Invalid string length

- refs: hexojs/hexo#4922

* fix lint
  • Loading branch information
yoshinorin committed Apr 13, 2022
1 parent c84e59e commit b5a3ba7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
"author": "Tommy Chen <tommy351@gmail.com> (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": {
Expand Down

0 comments on commit b5a3ba7

Please sign in to comment.