在哪里可以找到有关knex错误类型的文档? [英] Where can I find documentation for the types of knex errors?

查看:91
本文介绍了在哪里可以找到有关knex错误类型的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在互联网上进行搜索,但是似乎找不到关于不同类型的Knex错误的文档.

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.

推荐答案

@Mikael说的话.这是一个通行证.对于SQLite,在此处

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

db错误代码作为属性.errno包含在抛出的异常对象上.我使用它和db驱动程序文档通过以下功能来更详细地说明错误:

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

这篇关于在哪里可以找到有关knex错误类型的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆