Permalink
Browse files

[BUG] Proper error handling

  • Loading branch information...
1 parent c68a8b2 commit 9a7506630fe222e21c6c29d03d414a80fa46338f @masuidrive committed Apr 24, 2010
Showing with 38 additions and 8 deletions.
  1. +36 −6 lib/mysql.js
  2. +2 −2 test/test.real_mysql.js
View
@@ -95,7 +95,12 @@ Connection.prototype.query = function(sql, callback, errback) {
this.get_result()
.addCallback(utils.scope(this, function(rows) {
this.server_status = this.protocol.server_status;
- if(callback) callback(rows);
+ try {
+ if(callback) callback(rows);
+ }
+ catch(error) {
+ (errback || this.defaultErrback)(error);
+ }
}))
.addErrback(errback || this.defaultErrback);
}))
@@ -108,7 +113,12 @@ Connection.prototype.query = function(sql, callback, errback) {
result.server_status = this.server_status = this.protocol.server_status;
result.warning_count = this.warning_count = this.protocol.warning_count;
result.info = this.info = this.protocol.message;
- if(callback) callback(result);
+ try {
+ if(callback) callback(result);
+ }
+ catch(error) {
+ (errback || this.defaultErrback)(error);
+ }
}
}))
.addErrback(errback || this.defaultErrback);
@@ -157,7 +167,12 @@ Connection.prototype.next_result = function(callback, errback) {
this.result_exist = true;
this.get_result()
.addCallback(utils.scope(this, function(results) {
- callback(results);
+ try {
+ if(callback) callback(results);
+ }
+ catch(error) {
+ (errback || this.defaultErrback)(error);
+ }
}))
.addErrback(errback || this.defaultErrback);
}))
@@ -197,7 +212,12 @@ Stmt.prototype.prepare = function(query, callback, errback) {
this.fields = field_packets.map(function(field_packet) {
return new Field(field_packet);
});
- callback(this);
+ try {
+ if(callback) callback(this);
+ }
+ catch(error) {
+ (errback || this.defaultErrback)(error);
+ }
}))
.addErrback(errback || this.defaultErrback);
}
@@ -222,7 +242,12 @@ Stmt.prototype.execute = function(args, callback, errback) {
this.protocol.stmt_retr_all_records(fields, this.charset)
.addCallback(utils.scope(this, function(records) {
this.result.records = records;
- callback(this.result);
+ try {
+ callback(this.result);
+ }
+ catch(error) {
+ (errback || this.defaultErrback)(error);
+ }
}))
.addErrback(errback || this.defaultErrback);
}))
@@ -234,7 +259,12 @@ Stmt.prototype.execute = function(args, callback, errback) {
this.server_status = this.protocol.server_status;
this.warning_count = this.protocol.warning_count;
this.info = this.protocol.message;
- callback();
+ try {
+ callback();
+ }
+ catch(error) {
+ (errback || this.defaultErrback)(error);
+ }
}
}))
.addErrback(errback || this.defaultErrback);
@@ -179,7 +179,8 @@ var test_result1 = function() {
promise.emitSuccess();
},
function(error) {
- assert.ok(false);
+ conn.close();
+ promise.emitFailure();
});
return promise;
@@ -200,7 +201,6 @@ var test_insert256rows = function() {
q.push("("+i+")");
}
conn.query("INSERT INTO t(id) VALUES "+q.join(","), function(result) {
- assert.equal(1,2);
assert.equal(256, result.affected_rows);
});

0 comments on commit 9a75066

Please sign in to comment.