Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Better error handling plus debug logging for the import tool
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-palmer committed Feb 8, 2018
1 parent 147361b commit 97a9d49
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions import.js
Expand Up @@ -56,10 +56,18 @@ async function importTransactionFile(filePath, addressString, defaultPort) {

helpers.log(consts.LOG_INFO, `(${i + 1}/${trxCount}) ${trx.assetPath}`);

await client.beginTransaction(guid, hash);
try {
helpers.log(consts.LOG_DBG, `Begin transaction for ${helpers.GUIDBufferToString(guid)}-${hash.toString('hex')}`);
await client.beginTransaction(guid, hash);
}
catch (err) {
helpers.log(consts.LOG_ERR, err);
process.exit(1);
}

let stats;

for(let file of trx.files) {
let stats;
for (let file of trx.files) {

try {
stats = await fs.stat(file.path);
Expand All @@ -69,19 +77,34 @@ async function importTransactionFile(filePath, addressString, defaultPort) {
continue;
}

if(program.timestampCheck && stats.mtimeMs !== file.ts * 1000) {
if (program.timestampCheck && stats.mtimeMs !== file.ts * 1000) {
helpers.log(consts.LOG_WARN, `${file.path} has been modified, skipping`);
continue;
}

try {
const stream = fs.createReadStream(file.path);
helpers.log(consts.LOG_DBG, `Putting file of type: ${file.type} size: ${stats.size}`);
await client.putFile(file.type, guid, hash, stream, stats.size);
}
catch(err) {
helpers.log(consts.LOG_ERR, err);
process.exit(1);
}

sentBytes += stats.size;
const stream = fs.createReadStream(file.path);
await client.putFile(file.type, guid, hash, stream, stats.size);
sentFileCount ++;
sentFileCount++;
}

await client.endTransaction();
sentAssetCount++;
try {
helpers.log(consts.LOG_DBG, `End transaction for ${helpers.GUIDBufferToString(guid)}-${hash.toString('hex')}`);
await client.endTransaction();
sentAssetCount++;
}
catch (err) {
helpers.log(consts.LOG_ERR, err);
process.exit(1);
}
}

let totalTime = (Date.now() - startTime) / 1000;
Expand Down

0 comments on commit 97a9d49

Please sign in to comment.