在哪里可以找到有关 knex 错误类型的文档?
Where can I find documentation for the types of knex errors?
我已经在互联网上搜索过了,但似乎找不到关于不同类型的 Knex 错误的文档。
我想知道这些,以便我可以为我的项目实施正确的错误处理。我在哪里可以找到这个?他们简要提到了查询错误对象 here 但没有给出进一步的深度。我错过了什么吗?对我来说,他们应该有充分的记录是很基本的。
没有关于 knex 抛出的不同错误的文档。 knex 实际创建错误的地方并不多,通常是它产生错误的其他一些包,除了一些验证所选驱动程序支持的功能。
如果查询失败,knex 只会传递数据库驱动程序抛出的原始错误。
@Mikael 说的。这是一个穿越。对于 SQLite,有数据库错误列表 here and here。
数据库错误代码作为属性 .errno
包含在抛出的异常对象中。我使用这个和 db 驱动程序文档来更详细地说明以下函数的错误:
/**
* Gets Error strings using DB driver error number
* @param {number} errNo Database error number
* returns {object} errs: {"int":"Internal use string", "ext":"External usage string"};
*/
function getDBError(errNo) {
if (!errNo) {errNo = 0; };
let errs = {"int":null, "ext":null};
switch(errNo) {
case 2: errs.int="Internal logic error in SQLite"; break;
case 3: errs.int="Access permission denied"; break;
case 4: errs.int="Callback routine requested an abort"; break;
case 5: errs.int="The database file is locked"; break;
case 6: errs.int="A table in the database is locked"; break;
case 7: errs.int="A malloc() failed"; break;
case 8: errs.int="Attempt to write a readonly database"; break;
case 9: errs.int="Operation terminated by sqlite3_interrupt()"; break;
case 10: errs.int="Some kind of disk I/O error occurred"; break;
case 11: errs.int="The database disk image is malformed"; break;
case 12: errs.int="Unknown opcode in sqlite3_file_control()"; break;
case 13: errs.int="Insertion failed because database is full"; break;
case 14: errs.int="Unable to open the database file"; break;
case 15: errs.int="Database lock protocol error"; break;
case 16: errs.int="Database is empty"; break;
case 17: errs.int="The database schema changed"; break;
case 18: errs.int="String or BLOB exceeds size limit"; break;
case 19: errs.int="Abort due to constraint violation"; break;
case 20: errs.int="Data type mismatch"; break;
case 21: errs.int="Library used incorrectly"; break;
case 22: errs.int="Uses OS features not supported on host"; break;
case 23: errs.int="Authorization denied"; break;
case 24: errs.int="Auxiliary database format error"; break;
case 25: errs.int="2nd parameter to sqlite3_bind out of range"; break;
case 26: errs.int="File opened that is not a database file"; break;
case 27: errs.int="Notifications from sqlite3_log()"; break;
case 28: errs.int="Warnings from sqlite3_log()"; break;
case 100: errs.int="sqlite3_step() has another row ready"; break;
case 101: errs.int="sqlite3_step() has finished executing"; break;
case 301: errs.int="no such column"; break;
case 302: errs.int="no such table"; break;
case 303: errs.int="Cannot start a transaction within a transaction"; break;
default: errs.int="Database processing Error #"+errNo; break;
}
// errs.ext is future use to include end user messages and is currently ignored
if (!errs.ext) {errs.ext = errs.int; };
return errs;
};
我已经在互联网上搜索过了,但似乎找不到关于不同类型的 Knex 错误的文档。
我想知道这些,以便我可以为我的项目实施正确的错误处理。我在哪里可以找到这个?他们简要提到了查询错误对象 here 但没有给出进一步的深度。我错过了什么吗?对我来说,他们应该有充分的记录是很基本的。
没有关于 knex 抛出的不同错误的文档。 knex 实际创建错误的地方并不多,通常是它产生错误的其他一些包,除了一些验证所选驱动程序支持的功能。
如果查询失败,knex 只会传递数据库驱动程序抛出的原始错误。
@Mikael 说的。这是一个穿越。对于 SQLite,有数据库错误列表 here and here。
数据库错误代码作为属性 .errno
包含在抛出的异常对象中。我使用这个和 db 驱动程序文档来更详细地说明以下函数的错误:
/**
* Gets Error strings using DB driver error number
* @param {number} errNo Database error number
* returns {object} errs: {"int":"Internal use string", "ext":"External usage string"};
*/
function getDBError(errNo) {
if (!errNo) {errNo = 0; };
let errs = {"int":null, "ext":null};
switch(errNo) {
case 2: errs.int="Internal logic error in SQLite"; break;
case 3: errs.int="Access permission denied"; break;
case 4: errs.int="Callback routine requested an abort"; break;
case 5: errs.int="The database file is locked"; break;
case 6: errs.int="A table in the database is locked"; break;
case 7: errs.int="A malloc() failed"; break;
case 8: errs.int="Attempt to write a readonly database"; break;
case 9: errs.int="Operation terminated by sqlite3_interrupt()"; break;
case 10: errs.int="Some kind of disk I/O error occurred"; break;
case 11: errs.int="The database disk image is malformed"; break;
case 12: errs.int="Unknown opcode in sqlite3_file_control()"; break;
case 13: errs.int="Insertion failed because database is full"; break;
case 14: errs.int="Unable to open the database file"; break;
case 15: errs.int="Database lock protocol error"; break;
case 16: errs.int="Database is empty"; break;
case 17: errs.int="The database schema changed"; break;
case 18: errs.int="String or BLOB exceeds size limit"; break;
case 19: errs.int="Abort due to constraint violation"; break;
case 20: errs.int="Data type mismatch"; break;
case 21: errs.int="Library used incorrectly"; break;
case 22: errs.int="Uses OS features not supported on host"; break;
case 23: errs.int="Authorization denied"; break;
case 24: errs.int="Auxiliary database format error"; break;
case 25: errs.int="2nd parameter to sqlite3_bind out of range"; break;
case 26: errs.int="File opened that is not a database file"; break;
case 27: errs.int="Notifications from sqlite3_log()"; break;
case 28: errs.int="Warnings from sqlite3_log()"; break;
case 100: errs.int="sqlite3_step() has another row ready"; break;
case 101: errs.int="sqlite3_step() has finished executing"; break;
case 301: errs.int="no such column"; break;
case 302: errs.int="no such table"; break;
case 303: errs.int="Cannot start a transaction within a transaction"; break;
default: errs.int="Database processing Error #"+errNo; break;
}
// errs.ext is future use to include end user messages and is currently ignored
if (!errs.ext) {errs.ext = errs.int; };
return errs;
};