Skip to content

Conversation

Aschen
Copy link
Contributor

@Aschen Aschen commented Jan 28, 2021

What does this PR do?

Improve SDK stacktrace by highlighting the user code and displaying Kuzzle stacktrace as well.

How should this be manually tested?

const { Kuzzle, Http, WebSocket } = require('./index');

const kuzzle = new Kuzzle(new WebSocket('localhost'));

function executeQuery () {
  return kuzzle.query({
    controller: 'greeting',
    action: 'sayHello'
  });
}

(async () => {
  try {
    await kuzzle.connect();
    await executeQuery();
  }
  catch (error) {
    console.error(error)
  }
  finally {
    kuzzle.disconnect();
  }
})();

If Kuzzle is running in development mode then we display both stacktrace:

NotFoundError: API controller "greeting" not found.
    [...Kuzzle internal calls deleted...]
    at Funnel.getController (/var/app/node_modules/kuzzle/lib/api/funnel.js:595:24)
    at Funnel.processRequest (/var/app/node_modules/kuzzle/lib/api/funnel.js:409:29)
    at /var/app/node_modules/kuzzle/lib/api/funnel.js:285:27
          |
          |
          WebSocketProtocol
          |
          |
       at WebSocketProtocol.query (/home/aschen/projets/kuzzleio/sdk-javascript/src/protocols/abstract/Base.ts:127:19)
       at Proxy.query (/home/aschen/projets/kuzzleio/sdk-javascript/src/Kuzzle.ts:598:26)
>    at executeQuery (/home/aschen/projets/kuzzleio/sdk-javascript/test.js:6:17)
>    at /home/aschen/projets/kuzzleio/sdk-javascript/test.js:15:11
       at processTicksAndRejections (internal/process/task_queues.js:97:5)

If Kuzzle is not running in development mode we display only SDK stacktrace:

[KuzzleError: API controller "greeting" not found.
       at WebSocketProtocol.query (/home/aschen/projets/kuzzleio/sdk-javascript/src/protocols/abstract/Base.ts:127:19)
       at Proxy.query (/home/aschen/projets/kuzzleio/sdk-javascript/src/Kuzzle.ts:598:26)
>    at executeQuery (/home/aschen/projets/kuzzleio/sdk-javascript/test.js:6:17)
>    at /home/aschen/projets/kuzzleio/sdk-javascript/test.js:15:11
       at processTicksAndRejections (internal/process/task_queues.js:97:5)

Other changes

Boyscout

@codecov
Copy link

codecov bot commented Jan 28, 2021

Codecov Report

Merging #596 (b24b138) into 7-dev (4fb7d3b) will decrease coverage by 8.21%.
The diff coverage is 83.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##            7-dev     #596      +/-   ##
==========================================
- Coverage   95.57%   87.35%   -8.22%     
==========================================
  Files          32       33       +1     
  Lines        1310     1479     +169     
  Branches        0      260     +260     
==========================================
+ Hits         1252     1292      +40     
- Misses         58      136      +78     
- Partials        0       51      +51     
Impacted Files Coverage Δ
src/controllers/Document.ts 68.47% <68.47%> (ø)
src/controllers/Bulk.ts 70.58% <70.58%> (ø)
src/core/security/Role.ts 71.42% <71.42%> (ø)
src/controllers/Auth.ts 72.83% <72.83%> (ø)
src/controllers/Security.js 94.92% <75.00%> (-2.14%) ⬇️
src/controllers/Collection.ts 75.43% <75.43%> (ø)
src/controllers/Index.ts 76.19% <76.19%> (ø)
src/core/searchResult/SearchResultBase.ts 77.19% <76.92%> (ø)
src/protocols/abstract/Realtime.ts 97.14% <83.33%> (ø)
src/controllers/Base.ts 87.50% <87.50%> (ø)
... and 44 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bac7d5e...b24b138. Read the comment docs.

@Leodau Leodau linked an issue Jan 28, 2021 that may be closed by this pull request
// the SDK one
if (apiError.stack) {
this.stack = apiError.stack + '\n';
this.stack += ' |\n';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put just one |\n.

@Aschen Aschen merged commit 89ff5b1 into 7-dev Jan 29, 2021
@Aschen Aschen deleted the error-stacktrace-overhaul branch January 29, 2021 09:01
@Aschen Aschen mentioned this pull request Jan 29, 2021
Aschen added a commit that referenced this pull request Jan 29, 2021
# [7.5.3](https://github.com/kuzzleio/sdk-javascript/releases/tag/7.5.3) (2021-01-29)


#### Enhancements

- [ [#596](#596) ] Error stacktrace overhaul   ([Aschen](https://github.com/Aschen))
- [ [#595](#595) ] Allows to not send realtime notification on document controller   ([Aschen](https://github.com/Aschen))
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error stacktrace overhaul

3 participants