dougwilson / nodejs-depd

Deprecate all the things
MIT License
325 stars 87 forks source link

line info is not help #21

Closed atian25 closed 7 years ago

atian25 commented 7 years ago

egg deprecated ctx.isAjax is deprecated internal/process/next_tick.js:103:7

dougwilson commented 7 years ago

Hi @atian25 can you provide some more details? I see you're in @eggjs and so I assume you are trying to add this module to that module? Typically when you see a non-useful stack, it's because the following note was missed in the README:

[...] this module uses the calling file to get the boundary for the call stacks, so you should always create a new deprecate object in each file and not within some central file.

I can take a look to see what is happening if you have code I can try, though.

atian25 commented 7 years ago

thanks, we use it at https://github.com/eggjs/egg-core/blob/master/lib/egg.js#L156

I'll read the doc again, thanks~

dougwilson commented 7 years ago

Gotcha. Yea, you cannot use this module in that way in order for the stack traces to make sense. You should always create a new deprecate object in each file you are deprecating items, because that is how the file boundary is determined. If you create it in a single, central file, then the module will latch to that file as the stack boundary and then you'll end up with useless stack traces.

dougwilson commented 7 years ago

The usage in https://github.com/eggjs/egg-core/blob/1dda9fa9d1d61a1d06913202294ac8690dbef90d/lib/loader/file_loader.js is how the module needs to be loaded: you require('depd')(namespace) at the top of the file and only ever invoke the deprecate function within that same file.

It is not clear to me where you're using the deprecate property in that file you linked to, but the essence is that you cannot centralize the creation of this module like you're doing there.

atian25 commented 7 years ago

egg has plugin system, so we define a getter of app.deprecate then plugins and apps can use like this.app.deprecate()

https://github.com/eggjs/egg/blob/984d7320881adf9420e5c7e49d62d5530ad887dd/lib/egg.js#L319

dougwilson commented 7 years ago

Hi @atian25 thanks. So it's not possible to use this module in that way, as per the readme instructions. For the file https://github.com/eggjs/egg/blob/984d7320881adf9420e5c7e49d62d5530ad887dd/lib/egg.js you need to

  1. Add const deprecate = require('depd')('egg') at the top
  2. Change the line you referenced to deprecate('please use app.config.env instead')
atian25 commented 7 years ago

got, thanks for reply timely.

dougwilson commented 7 years ago

@atian25 no problem :) I happened to be up and about on GitHub 👍