``$requestStack->getMasterRequest()`` can return ``null`` when you are outside the request scope. You need to handle this case