Skip to content

Commit

Permalink
fix: 🐛 check error code to prevent data loss
Browse files Browse the repository at this point in the history
  • Loading branch information
64b2b6d12bfe4baae7dad3d01 authored and juanpicado committed Aug 26, 2017
1 parent 5e8b268 commit 5d73dca
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lib/storage/local/local-data.js
Expand Up @@ -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}`);
}
}
}

Expand Down

0 comments on commit 5d73dca

Please sign in to comment.