Where can I find documentation for the types of knex errors?

こ雲淡風輕ζ 提交于 2020-01-17 02:19:27

问题


I've scoured the internet but it seems that I can't find documentation for the different types of Knex errors.

I would like to know these so I can implement proper error handling for my project. Where can I find this? They briefly mention the query error object here but no further depth is given. Am I missing something? It seems basic to me that they should have this well-documented.


回答1:


What @Mikael said. It's a passthrough. For SQLite there are lists of DB errors here and here.

The db error code is included on the thrown exception object as the attribute .errno. I use this and the db driver documentation to be more verbose about the errors with the following function:

/**
 * 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;
};



回答2:


There is no documentation of different errors thrown by knex. There are not that many places where knex actually creates Errors, usually its some other package where error is originated, except for some validations that feature is supported by the selected driver.

If a query fails, knex just passes the original error that was thrown by the database driver.



来源:https://stackoverflow.com/questions/52684205/where-can-i-find-documentation-for-the-types-of-knex-errors

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!