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

transChoice method is deprecated in Symfony 4.2 #188

Closed
michaelcopeland opened this issue Feb 12, 2019 · 12 comments
Closed

transChoice method is deprecated in Symfony 4.2 #188

michaelcopeland opened this issue Feb 12, 2019 · 12 comments

Comments

@michaelcopeland
Copy link

Hello,

I wanted to add this here to provide heads up/help someone else since I was able to fix this issue (hopefully correctly).

I recently upgraded from sentry-laravel 0.7.0 to 1.0.0-beta3 as per the integration guide. All appeared to work well since updating until visiting a inner blade page that makes use thujohn/twitter's ago method (\Thujohn\Twitter\Facades\Twitter::ago($user->updated_at)). This page was now heavily broken as some HTML tags weren't closed (since the exception was thrown) as well as the updated_at data being missing. It appears the deprecation is being treated as an exception (see references below).

Upon removing "sentry/sentry-laravel": "1.0.0-beta3" from composer.json things work correctly. 0.7.0 also previously worked correctly.

My fix:
Instead of downgrading symfony/translation as per reference 1, I was able to correct this by adding "\Symfony\Component\Translation\Translator::transChoice," to the $dontReport array within app/Exceptions/Handler.php. I'm hoping this won't cause any other funny business within the application.

Full error:
User Deprecated: The "Symfony\Component\Translation\Translator::transChoice()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%count%" parameter.

References:
briannesbitt/Carbon#1548
symfony/symfony#29607

@stayallive
Copy link
Collaborator

stayallive commented Feb 13, 2019

This sounds like when you when downgraded to sentry-laravel:0.7.x you also downgraded the Symfony translation package? I'm not sure Sentry does anything different since 0.7.x in this regard.

Sentry should never interrupt the request, ever. It looks like the Laravel error handler is the culprit here converting the notice to an exception (which is in the end also captured by Sentry).

However, I will keep this open so we can investigate and see if we can replicate the behaviour.

@michaelcopeland
Copy link
Author

Hey @stayallive,

To clarify a bit, I didn't have to downgrade to sentry-laravel:0.7.0 and I'm still using sentry-laravel:1.0.0-beta3.

I've run a composer show -i and it appears that symfony/translation is still at v4.2.3. I believe when sentry-laravel:0.7.0 was in use my app may have been using symfony/translation:4.1.x at the time.

I hope this helps and thanks a lot for your time/attention. Please let me know if I can help further.

@jiriko
Copy link

jiriko commented Feb 14, 2019

+1 same problem.

@stayallive
Copy link
Collaborator

stayallive commented Feb 14, 2019

I have installed a clean Laravel 5.7 to test this issue and followed the installation instructions: https://docs.sentry.io/platforms/php/laravel/#laravel-5x (made no changes to any config).

I tested the following route:

Route::get('/', function () {
    @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%%count%%" parameter.', __METHOD__), E_USER_DEPRECATED);

    return view('welcome');
});

And in that view used (made sure translations package is 4.2.x):

{{ now()->diffForHumans() }}

And couldn't trigger the deprecation to show up as ErrorException (or breaking the view/app) or being sent to Sentry.

The following worked immediately (as expected):

Route::get('/', function () {
    throw new Exception('Pizza!');

    return view('welcome');
});

Hope you can possibly provide some more info or configuration that could trigger this exception.

Are you using the log channels? Did you make any changes in the config/sentry.php file? Did you make other changes to the Laravel error handler? Are you setting user context somewhere?

A stack trace of the error could help too so we can possibly see via which path it ended up being re-thrown.

@stayallive
Copy link
Collaborator

What is the PHP version you are running on?

And do you have a stacktrace for the error?

@jiriko
Copy link

jiriko commented Feb 14, 2019

try adding a user context to sentry earlier in the request before the trigger_error

PHP 7.2.0
laravel/framework v5.7.24
sentry/sentry 2.0.0-beta1
sentry/sentry-laravel 1.0.0-beta3

public function report(Exception $exception)
    {
        if (app()->bound('sentry') && $this->shouldReport($exception)) {
                      app('sentry')->captureException($exception);
          }

        parent::report($exception);
    }
class SentryContext
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  \Closure $next
    * @return mixed
     */
    public function handle($request, Closure $next)
   {

            app('sentry')->getCurrent()->configureScope(function (Scope $scope): void {
                $scope->setUser(['email' => 'foo@gmail.com']);
           });


       return $next($request);
   }
}
ErrorException: User Deprecated: The "Symfony\Component\Translation\Translator::transChoice()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%count%" parameter.
#86 vendor/symfony/translation/Translator.php(229): Symfony\Component\Translation\Translator::transChoice
#85 vendor/nesbot/carbon/src/Carbon/Carbon.php(4178): Carbon\Carbon::diffForHumans
#84 vendor/laravel/framework/src/Illuminate/Support/Optional.php(127): Illuminate\Support\Optional::__call
#83 app/Http/Resources/UserResource.php(26): App\Http\Resources\UserResource::toArray
#82 vendor/laravel/framework/src/Illuminate/Http/Resources/Json/JsonResource.php(90): Illuminate\Http\Resources\Json\JsonResource::resolve
#81 vendor/laravel/framework/src/Illuminate/Http/Resources/Json/JsonResource.php(207): Illuminate\Http\Resources\Json\JsonResource::jsonSerialize
#80 [internal](0): json_encode
#79 /shared/storage/framework/views/2928c4558d81633145e95ae2aa336277c83a95ab.php(71): include
#78 vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): Illuminate\View\Engines\PhpEngine::evaluatePath
#77 vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\CompilerEngine::get
#76 vendor/laravel/framework/src/Illuminate/View/View.php(142): Illuminate\View\View::getContents
#75 vendor/laravel/framework/src/Illuminate/View/View.php(125): Illuminate\View\View::renderContents
#74 vendor/laravel/framework/src/Illuminate/View/View.php(90): Illuminate\View\View::render
prod/shared/storage/framework/views/43eb01d6c8c04727b591e10735aeda9dc67172b7.php(63): include
#72 vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): Illuminate\View\Engines\PhpEngine::evaluatePath
#71 vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\CompilerEngine::get
#70 vendor/laravel/framework/src/Illuminate/View/View.php(142): Illuminate\View\View::getContents
#69 vendor/laravel/framework/src/Illuminate/View/View.php(125): Illuminate\View\View::renderContents
#68 vendor/laravel/framework/src/Illuminate/View/View.php(90): Illuminate\View\View::render
#67 vendor/laravel/framework/src/Illuminate/Http/Response.php(42): Illuminate\Http\Response::setContent
#66 vendor/symfony/http-foundation/Response.php(202): Symfony\Component\HttpFoundation\Response::__construct
#65 vendor/laravel/framework/src/Illuminate/Routing/Router.php(750): Illuminate\Routing\Router::toResponse
#64 vendor/laravel/framework/src/Illuminate/Routing/Router.php(722): Illuminate\Routing\Router::prepareResponse
#63 vendor/laravel/framework/src/Illuminate/Routing/Router.php(682): Illuminate\Routing\Router::Illuminate\Routing\{closure}
#62 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#61 app/Http/Middleware/UserReady.php(23): App\Http\Middleware\UserReady::handle
#60 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#59 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#58 app/Http/Middleware/SentryContext.php(25): App\Http\Middleware\SentryContext::handle
#57 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#56 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#55 vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Middleware\SubstituteBindings::handle
#54 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#53 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#52 vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\Auth\Middleware\Authenticate::handle
#51 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#50 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#49 vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(75): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::handle
#48 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#47 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#46 vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\View\Middleware\ShareErrorsFromSession::handle
#45 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#44 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#43 vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\Session\Middleware\StartSession::handle
#42 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#41 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#40 vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::handle
#39 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#38 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#37 vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Cookie\Middleware\EncryptCookies::handle
#36 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#35 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#34 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): Illuminate\Pipeline\Pipeline::then
#33 vendor/laravel/framework/src/Illuminate/Routing/Router.php(684): Illuminate\Routing\Router::runRouteWithinStack
#32 vendor/laravel/framework/src/Illuminate/Routing/Router.php(659): Illuminate\Routing\Router::runRoute
#31 vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\Routing\Router::dispatchToRoute
#30 vendor/laravel/framework/src/Illuminate/Routing/Router.php(614): Illuminate\Routing\Router::dispatch
#29 vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Foundation\Http\Kernel::Illuminate\Foundation\Http\{closure}
#28 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#27 app/Http/Middleware/TransactionalRequest.php(29): App\Http\Middleware\TransactionalRequest::handle
#26 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#25 vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Routing\Pipeline::Illuminate\Routing\{closure}
#24 app/Http/Middleware/BrowserCheck.php(41): App\Http\Middleware\BrowserCheck::handle
#23 vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(151): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}

@stayallive
Copy link
Collaborator

@jiriko thanks for all the info! I'm getting somewhere with this 👍

@stayallive
Copy link
Collaborator

@jiriko can you upgrade to the latest beta versions and see if it's still there?

sentry/sentry-laravel 1.0.0-beta4 (which should install sentry/sentry 2.0.0-beta2)

@jiriko
Copy link

jiriko commented Feb 14, 2019

it keeps sending the error

User Deprecated: The "Symfony\Component\Translation\Translator::transChoice()"

to sentry but the application now works fine

@stayallive
Copy link
Collaborator

stayallive commented Feb 14, 2019

@jiriko yes, that's expected. Sentry is logging exceptions and errors (a deprecation is triggered by trigger_error). You can disable that by adding the following in your config/sentry.php:

    'error_types' => E_ALL & ~E_USER_DEPRECATED,

This means send everyting except deprecation notices.

Our default is to log E_ALL.

@jiriko
Copy link

jiriko commented Feb 14, 2019

@stayallive perfect! thank you so much

@stayallive
Copy link
Collaborator

stayallive commented Feb 14, 2019

@jiriko No problem, going to close this issue since was already fixed.


If you are still having issues make sure you are on 1.0.0-beta4 or higher!

If you don't want deprecated notices being sent to Sentry read: #188 (comment)

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

No branches or pull requests

3 participants