Skip to content

Commit f69cc97

Browse files
swallow error for automatic rollback
1 parent 5999e09 commit f69cc97

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

lib/datastore/transaction.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,10 @@ Transaction.prototype.commit = function(callback) {
200200
this.request_(protoOpts, reqOpts, function(err, resp) {
201201
if (err) {
202202
// Rollback automatically for the user.
203-
self.rollback(function(err) {
204-
if (err) {
205-
err.message = [
206-
'The commit was not successful and the transaction could not be',
207-
'rolled back. You may want to try calling transaction.rollback().',
208-
'\n',
209-
'\n',
210-
err.message
211-
].join('');
212-
}
213-
214-
// Provide the response items from the failed commit to the user. A
215-
// successful rollback should be transparent.
203+
self.rollback(function() {
204+
// Provide the response items from the failed commit to the user. Even
205+
// a failed rollback should be transparent.
206+
// RE: https://github.com/GoogleCloudPlatform/gcloud-node/pull/1369#discussion_r66833976
216207
callback(err, resp);
217208
});
218209
return;

test/datastore/transaction.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,27 @@ describe('Transaction', function() {
161161
transaction.commit(done);
162162
});
163163

164-
it('should pass error to callback', function(done) {
164+
describe('errors', function() {
165165
var error = new Error('Error.');
166-
transaction.request_ = function(protoOpts, reqOpts, callback) {
167-
callback = callback || reqOpts;
168-
callback(error);
169-
};
170-
transaction.commit(function(err) {
171-
assert.deepEqual(err, error);
172-
done();
166+
var apiResponse = {};
167+
168+
beforeEach(function() {
169+
transaction.rollback = function(callback) {
170+
callback();
171+
};
172+
173+
transaction.request_ = function(protoOpts, reqOpts, callback) {
174+
callback = callback || reqOpts;
175+
callback(error, apiResponse);
176+
};
177+
});
178+
179+
it('should pass the error to the callback', function(done) {
180+
transaction.commit(function(err, resp) {
181+
assert.strictEqual(err, error);
182+
assert.strictEqual(resp, apiResponse);
183+
done();
184+
});
173185
});
174186
});
175187

0 commit comments

Comments
 (0)