Skip to content

Commit

Permalink
Better error messages AlaSQL#640
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasrw committed Apr 1, 2016
1 parent e50ca78 commit c209436
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 37 deletions.
4 changes: 2 additions & 2 deletions dist/alasql-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! AlaSQL v0.2.5-develop-1260 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
//! AlaSQL v0.2.5-develop-1262 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
/*
@module alasql
@version 0.2.5-develop-1260
@version 0.2.5-develop-1262
AlaSQL - JavaScript SQL database
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
Expand Down
2 changes: 1 addition & 1 deletion dist/alasql-worker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions dist/alasql.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! AlaSQL v0.2.5-develop-1260 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
//! AlaSQL v0.2.5-develop-1262 | © 2014-2016 Andrey Gershun & Mathias Rangel Wulff | License: MIT
/*
@module alasql
@version 0.2.5-develop-1260
@version 0.2.5-develop-1262

AlaSQL - JavaScript SQL database
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
Expand Down Expand Up @@ -126,7 +126,7 @@ var alasql = function alasql(sql, params, cb, scope) {
Current version of alasql
@constant {string}
*/
alasql.version = '0.2.5-develop-1260';
alasql.version = '0.2.5-develop-1262';

/**
Debug flag
Expand Down Expand Up @@ -8235,6 +8235,11 @@ yy.Select.prototype.compileSelect1 = function(query) {
if(xcolumns && columns.length > 0) {

var tcol = xcolumns[col.columnid];

if(undefined === tcol){
throw new Error("Column does not exists: "+col.columnid);;
}

var coldef = {
columnid:col.as || col.columnid,
dbtypeid:tcol.dbtypeid,
Expand Down Expand Up @@ -8904,6 +8909,10 @@ yy.Select.prototype.compileDefCols = function(query, databaseid) {

var table = alasql.databases[fr.databaseid || databaseid].tables[fr.tableid];

if(undefined === table){
throw new Error("Table does not exists: "+fr.tableid);;
}

if(table.columns) {
table.columns.forEach(function(col){
if(defcols[col.columnid]) {
Expand Down
28 changes: 14 additions & 14 deletions dist/alasql.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/424select.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ yy.Select.prototype.compileSelect1 = function(query) {
if(xcolumns && columns.length > 0) {
// console.log(1);
var tcol = xcolumns[col.columnid];

if(undefined === tcol){
throw new Error("Column does not exists: "+col.columnid);;
}

var coldef = {
columnid:col.as || col.columnid,
dbtypeid:tcol.dbtypeid,
Expand Down
5 changes: 5 additions & 0 deletions src/44defcols.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ yy.Select.prototype.compileDefCols = function(query, databaseid) {
//console.log(alasql.databases);
var table = alasql.databases[fr.databaseid || databaseid].tables[fr.tableid];
//console.log(table);

if(undefined === table){
throw new Error("Table does not exists: "+fr.tableid);;
}

if(table.columns) {
table.columns.forEach(function(col){
if(defcols[col.columnid]) {
Expand Down
33 changes: 16 additions & 17 deletions test/test232.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,45 @@ if(typeof exports === 'object') {
__dirname = '.';
};

// See http://www.codeproject.com/Articles/300785/Calculating-simple-running-totals-in-SQL-Server
describe('Test 232 Errors handling', function() {

it('1. Prepare database', function(done){
before(function(){
alasql('CREATE DATABASE test232; USE test232;');
done();
});

after(function(){
alasql('set errorlog off');
alasql('DROP DATABASE test232');
});


it("2. Throw error", function(done) {
alasql('set errorlog off');
assert.throws(function(){
alasql('SELECT * FROM one', [], function(data,err){
/// console.log(err);
alasql('SELECT * FROM faultyName', [], function(data,err){
});
},Error);
done();
});

it("3. Log error async", function(done) {
alasql('set errorlog on');
alasql('SELECT * FROM one', [], function(data,err){
assert(err.message == "Cannot read property 'columns' of undefined");
alasql('SELECT * FROM faultyName', [], function(data,err){
assert(/^Table does not exists\:/.test(err.message));
done();
});
done();

});

it("4. Log error sync", function(done) {
it("4. Log error sync", function() {
alasql('set errorlog on');
alasql('SELECT * FROM one');
assert(alasql.error.message == "Cannot read property 'columns' of undefined");
alasql('SELECT * FROM faultyName');
assert(/^Table does not exists\:/.test(alasql.error.message));

alasql('SELECT * FROM ?',[{a:1},{a:2}]);
assert(!alasql.error);
done();
});

it('99. DROP', function(done){
alasql('set errorlog off');
alasql('DROP DATABASE test232');
done();
});

});

0 comments on commit c209436

Please sign in to comment.