Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spell should subclass Promise #174

Open
cyjake opened this issue Sep 15, 2021 · 1 comment
Open

Spell should subclass Promise #174

cyjake opened this issue Sep 15, 2021 · 1 comment

Comments

@cyjake
Copy link
Owner

cyjake commented Sep 15, 2021

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.

@cyjake
Copy link
Owner Author

cyjake commented Sep 16, 2021

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant