Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(workaround): RangeError: Invalid string length #123

Merged
merged 2 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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