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

[BUG] Exceptions (and descendants) have stack: undefined #2402

Closed
3 tasks
mistergreen-christopher opened this issue Aug 1, 2023 · 8 comments · Fixed by #2408
Closed
3 tasks

[BUG] Exceptions (and descendants) have stack: undefined #2402

mistergreen-christopher opened this issue Aug 1, 2023 · 8 comments · Fixed by #2408

Comments

@mistergreen-christopher
Copy link

Information

  • Version: 7.34.2
  • Packages: @tsed/exceptions

Currently, when throwing an Exception or descendant, the stack trace is undefined. Please see the below example and check the log response in the terminal (when running locally).

Example

import { Controller } from '@tsed/di'
import { Get } from '@tsed/schema'
import { Exception } from '@tsed/exceptions'

@Controller('/hello-world')
export class HelloWorldController {
  @Get('/')
  get() {
    throw new Exception()
  }
}

Log output

[2023-08-01T11:05:27.214] [ERROR] [TSED] - {
  method: 'GET',
  url: '/rest/items',
  route: '/rest/items',
  headers: {
    'content-type': 'application/json',
    'user-agent': 'PostmanRuntime/7.32.3',
    accept: '*/*',
    'postman-token': 'aa69983a-d99d-406d-9fa0-72c39d5ea5b1',
    host: 'localhost:8083',
    'accept-encoding': 'gzip, deflate, br',
    connection: 'keep-alive',
    'content-length': '28'
  },
  body: { namee: 'Item name' },
  query: {},
  params: {},
  reqId: 'e94351b6a36a40b6b878515058e6b454',
  time: 2023-08-01T09:05:27.214Z,
  duration: 9,
  error: {
    name: 'INTERNAL_SERVER_ERROR',
    message: '',
    status: 500,
    errors: [],
    stack: undefined
  },
  stack: undefined
}

Suggested fix

Add super.captureStackTrace() in the constructor of the Exception class:

constructor(status: number = 500, message: string = "", origin?: Error | string | any) {

Please see Error.captureStackTrace for more details.

Acceptance criteria

  • Exception class should capture stack in constructor
  • Stack trace should be visible in log
  • Stack trace should be visible in response when Env.DEV === true
@Romakita
Copy link
Collaborator

Romakita commented Aug 1, 2023

@mistergreen-christopher Thanks for the issue. Can you open PR, please ?

@Romakita
Copy link
Collaborator

@mistergreen-christopher Based on the nodejs doc error.stack should do the same thing.

const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack` 

@github-actions
Copy link

🎉 Are you happy?

If you appreciated the support, know that it is free and is carried out on personal time ;)

A support, even a little bit makes a difference for me and continues to bring you answers!

github opencollective

@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 7.34.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Romakita
Copy link
Collaborator

Romakita commented Sep 6, 2023

🎉 This issue has been resolved in version 7.35.0-beta.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Romakita
Copy link
Collaborator

Romakita commented Sep 7, 2023

🎉 This issue has been resolved in version 7.35.0-rc.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 7.36.0-rc.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 7.36.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants