1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2025-02-21 07:29:37 +01:00

fix: 🐛 check error code to prevent data loss

This commit is contained in:
Meeeeow 2017-08-19 00:34:00 +08:00 committed by Juan Picado @jotadeveloper
parent 5e8b26893e
commit 5d73dcaf89
No known key found for this signature in database
GPG Key ID: 18AC54485952D158

@ -33,11 +33,13 @@ const logger = require('../../logger');
}
}
try {
this.data = JSON.parse(dbFile);
} catch(err) {
logger.logger.error(err);
throw new Error(`Package database file corrupted (invalid JSON), please fix it manually.\nFile Path: ${this.path}`);
if (dbFile) {
try {
this.data = JSON.parse(dbFile);
} catch(err) {
logger.logger.error(err);
throw new Error(`Package database file corrupted (invalid JSON), please fix it manually.\nFile Path: ${this.path}`);
}
}
}