@cloudant/couchbackup
Advanced tools
Comparing version 2.0.0-SNAPSHOT.54 to 2.0.0-SNAPSHOT.58
25
app.js
@@ -113,5 +113,5 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
// callback with the error set | ||
targetStream.on('error', function(obj) { | ||
debug('Error ' + JSON.stringify(obj)); | ||
if (callback) callback(obj, null); | ||
targetStream.on('error', function(err) { | ||
debug('Error ' + JSON.stringify(err)); | ||
if (callback) callback(err); | ||
}); | ||
@@ -151,5 +151,8 @@ | ||
}) | ||
.on('error', function(obj) { | ||
debug('Error ' + JSON.stringify(obj)); | ||
ee.emit('error', obj); | ||
.on('error', function(err) { | ||
if (error.codes()[err.name]) { | ||
return callback(err); // fatal error | ||
} | ||
debug('Error ' + JSON.stringify(err)); | ||
ee.emit('error', err); | ||
}) | ||
@@ -211,6 +214,8 @@ .on('finished', function(obj) { | ||
}) | ||
.on('error', function(e) { | ||
debug(' error', e); | ||
ee.emit('error', e); | ||
callback(e, writer); | ||
.on('error', function(err) { | ||
if (error.codes()[err.name]) { | ||
return callback(err); // fatal error | ||
} | ||
debug('Error ' + JSON.stringify(err)); | ||
ee.emit('error', err); | ||
}) | ||
@@ -217,0 +222,0 @@ .on('finished', function(obj) { |
@@ -51,4 +51,8 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
} else { | ||
spoolchanges(dbUrl, log, blocksize, function logFileGenerated() { | ||
downloadRemainingBatches(log, dbUrl, ee, start, batchesPerDownloadSession, parallelism); | ||
spoolchanges(dbUrl, log, blocksize, function(err) { | ||
if (err) { | ||
ee.emit('error', err); | ||
} else { | ||
downloadRemainingBatches(log, dbUrl, ee, start, batchesPerDownloadSession, parallelism); | ||
} | ||
}); | ||
@@ -55,0 +59,0 @@ } |
@@ -16,2 +16,14 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
// fatal errors | ||
const codes = { | ||
'InvalidOption': 2, | ||
'RestoreDatabaseNotFound': 10, | ||
'Unauthorized': 11, | ||
'Forbidden': 12, | ||
'NoLogFileName': 20, | ||
'LogDoesNotExist': 21, | ||
'IncompleteChangesInLogFile': 22, | ||
'SpoolChangesError': 30 | ||
}; | ||
module.exports = { | ||
@@ -24,14 +36,8 @@ BackupError: class BackupError extends Error { | ||
}, | ||
codes: function() { return Object.assign({}, codes); }, | ||
terminationCallback: function terminationCallback(err, data) { | ||
if (err) { | ||
process.on('uncaughtException', function(err) { | ||
var exitCode = { | ||
'InvalidOption': 2, | ||
'RestoreDatabaseNotFound': 10, | ||
'Unauthorized': 11, | ||
'NoLogFileName': 20, | ||
'LogDoesNotExist': 21 | ||
}[err.name] || 1; | ||
console.error(err.message); | ||
process.exitCode = exitCode; | ||
process.exitCode = codes[err.name] || 1; | ||
}); | ||
@@ -38,0 +44,0 @@ throw err; |
@@ -20,2 +20,3 @@ // Copyright © 2017 IBM Corp. All rights reserved. | ||
const change = require('./change.js'); | ||
const error = require('./error.js'); | ||
@@ -29,5 +30,3 @@ /** | ||
* @param {number} bufferSize - the number of changes per batch/log line | ||
* @param {function} callback - called when log is completed. Signature is | ||
* (err, {batches: batch, docs: doccount}), where batches is the total number | ||
* of batches and doccount is total number of changes found. | ||
* @param {function(err)} callback - a callback to run on completion | ||
*/ | ||
@@ -40,6 +39,4 @@ module.exports = function(dbUrl, log, bufferSize, callback) { | ||
var batch = 0; | ||
var doccount = 0; | ||
var lastSeq = null; | ||
var logStream = fs.createWriteStream(log); | ||
console.error('Streaming changes to disk:'); | ||
@@ -63,3 +60,2 @@ // send documents ids to the queue in batches of bufferSize + the last batch | ||
var obj = {id: c.id}; | ||
doccount++; | ||
buffer.push(obj); | ||
@@ -78,16 +74,26 @@ processBuffer(false); | ||
}; | ||
client(r) | ||
.pipe(liner()) | ||
var c = client(r); | ||
c.end(); | ||
c.on('response', function(resp) { | ||
if (resp.statusCode !== 200) { | ||
c.abort(); | ||
callback(new error.BackupError('SpoolChangesError', `ERROR: Changes request failed with status code ${resp.statusCode}`)); | ||
} else { | ||
console.error('Streaming changes to disk:'); | ||
} | ||
}).pipe(liner()) | ||
.pipe(change(onChange)) | ||
.on('finish', function() { | ||
processBuffer(true); | ||
logStream.write(':changes_complete ' + lastSeq + '\n'); | ||
logStream.end(); | ||
console.error(''); | ||
if (doccount === 0) { | ||
callback(new Error('zero documents found - nothing to do'), null); | ||
if (!lastSeq) { | ||
logStream.end(); | ||
callback(new error.BackupError('SpoolChangesError', `ERROR: Changes request terminated before last_seq was sent`)); | ||
} else { | ||
callback(null, {batches: batch, docs: doccount}); | ||
logStream.write(':changes_complete ' + lastSeq + '\n'); | ||
logStream.end(); | ||
callback(); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "@cloudant/couchbackup", | ||
"version": "2.0.0-SNAPSHOT.54", | ||
"version": "2.0.0-SNAPSHOT.58", | ||
"description": "CouchBackup - command-line backup utility for Cloudant/CouchDB", | ||
@@ -20,3 +20,3 @@ "homepage": "https://github.com/cloudant/couchbackup", | ||
"engines": { | ||
"node": ">=4.8.1" | ||
"node": ">=4.8.2" | ||
}, | ||
@@ -23,0 +23,0 @@ "dependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179329
3196