Skip to content

Make getContext softer #4536

@elibarzilay

Description

@elibarzilay

What is the feature you are proposing?

getContext is definitely useful right now, but only in the context of a request.

I'm guessing that one of its most popular uses is in a logging function -- but those can be called outside of a request context too, and then it throws an error. Using a try/catch is both extra runtime baggage and extra verbiage.

It would be simpler -- for such cases -- if it simply didn't throw the error.

Changing its type would most likely be problematic for existing code, and adding some flag to contextStorage would be ugly. So, a simpler solution is to add some new getContextIfAny which would be the same as getContext except for not throwing the error (so, a quick one-liner).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions