leoric
leoric copied to clipboard
Spell should subclass Promise
Currently Spell is a duck typed promise implementation by providing promise methods such as .then(), .catch(), and .finally(). It is convenient to customize the constructor and async logic in this way, but it loses stack trace comparing the native implementation.
- https://v8.dev/docs/stack-trace-api
With await + thenable objects, we can have decent stack trace already:
Error: ER_DUP_ENTRY: Duplicate entry '-1' for key 'articles.PRIMARY'
at Query.Sequence._packetToError (node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Query.ErrorPacket (node_modules/mysql/lib/protocol/sequences/Query.js:79:18)
at Protocol._parsePacket (node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (node_modules/mysql/lib/Connection.js:526:10)
at addChunk (internal/streams/readable.js:290:12)
at readableAddChunk (internal/streams/readable.js:265:9)
at Socket.Readable.push (internal/streams/readable.js:204:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
--------------------
at Protocol._enqueue (node_modules/mysql/lib/protocol/Protocol.js:144:48)
at PoolConnection.query (node_modules/mysql/lib/Connection.js:198:25)
at /Users/nil/Projects/cyjake/leoric/src/drivers/mysql/index.js:75:18
at new Promise (<anonymous>)
at MysqlDriver.query (src/drivers/mysql/index.js:74:21)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Spell.ignite (src/spell.js:654:18)
at async Context.<anonymous> (test/unit/spell.test.js:49:5)
The stack above -------------------- are the cause error, and the stack below it I believe is captured by mysqljs/mysql itself, with options.verbose turned on (which is the default).