Skip to content

Being able to receive warnings in custom handlers #250

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

Closed
eirslett opened this issue Feb 6, 2017 · 4 comments
Closed

Being able to receive warnings in custom handlers #250

eirslett opened this issue Feb 6, 2017 · 4 comments

Comments

@eirslett
Copy link

eirslett commented Feb 6, 2017

An example would be when using jquery-migrate in unit tests:

jQuery.migrateWarningHandler(warning => failTheUnitTest(warning))

or one could throw an exception possibly.

Migrate warnings would then fail the build, so problems are discovered early.

See This PR in jquery-ui for context.

(Ideally it would be possible to use both in 1.4.x and 3.x, since that is what jquery-ui uses)

@dmethvin
Copy link
Member

dmethvin commented Feb 6, 2017

See #15 and #196 for some approaches on this. I think they solve that use case? You can also patch console.warn and fail the test if you see JQMIGRATE in the message.

@eirslett
Copy link
Author

eirslett commented Feb 6, 2017

I cannot find issue #296 (in the jquery-migrate project), which one is that?
Yes, one could simply monkey-patch console.warn or jQuery.migrateWarnings.push, but I'm not sure it's a good idea - it relies on undocumented internal implementation details of jquery-migrate, which could be changed at any time. It would imply a strict requirement on jquery-migrate to never change its internal implementations.

@dmethvin
Copy link
Member

dmethvin commented Feb 6, 2017

Sorry I meant #196. I don't expect we'll change those details since we've advocated their use in several tickets at this point. If you'd like to use it and add a comment to that effect please file a PR.

Adding a handler interface is always more complicated that you might think, it needs to define what happens for multiple listeners and there's the possibility of recursion (e.g., a warning handler calling a jQuery method that itself generates a warning). Yes all of those things can be defined, guarded, or documented away but given the small number of use cases I think we have acceptable solutions already.

@eirslett
Copy link
Author

eirslett commented Feb 6, 2017

Ok, thank you for your responses! I will try to monkey-patch jQuery.migrateWarnings.push then.

@eirslett eirslett closed this as completed Feb 6, 2017
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

2 participants