heimdal icon indicating copy to clipboard operation
heimdal copied to clipboard

config:cache command crashes with add_context closure

Open san3jaya opened this issue 3 years ago • 0 comments

Using add_context giving closure error Screenshot from 2021-09-01 15-57-45

'sentry_options' => [
                    'add_context' => function ($exception) {

                        $context['environment'] = app()->environment();
                        try {
                            $context['release'] = \Tremby\LaravelGitVersion\GitVersionHelper::getVersion();
                        } catch (\Tremby\LaravelGitVersion\Exception\CouldNotGetVersionException $exception) {
                            $context['release'] = '';
                        } catch (\Throwable $throwable) {
                            $context['release'] = '';

                            $context['extra']['exceptions_in_exception_handler'][] = (string) $throwable;
                        }

                        try {
                            $user = \User::current();
                        } catch (\Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException $exception) {
                            $user = null;
                        } catch (\Throwable $throwable) {
                            $user = null;

                            $context['extra']['exceptions_in_exception_handler'][] = (string) $throwable;
                        }

                        if ($user) {
                            $context['user'] = [
                                'id' => $user->id,
                                'email' => $user->username,
                            ];
                        } else {
                            $context['user'] = [];
                        }

                        // When running in console request is not available
                        if (substr(php_sapi_name(), 0, 3) !== 'cli') {
                            $request = app('request');

                            if (!isset($context['extra'])) {
                                $context['extra'] = [];
                            }

                            $context['extra']['request_data'] = json_encode($request->all());

                            try {
                                $context['extra']['api_version'] = app()->get("ApiVersion")->version();
                            } catch (\Throwable $throwable) {
                                $context['extra']['api_version'] = "unknown";
                            }

                            try {
                                $context['user']['ip_address'] = \Request::getClientIp();
                            } catch (\Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException $exception) {
                                $context['user']['ip_address'] = '0.0.0.0';
                            } catch (\Throwable $throwable) {
                                $context['user']['ip_address'] = '0.0.0.0';

                                $context['extra']['exceptions_in_exception_handler'][] = (string) $throwable;
                            }
                        }

                        if (isset($context['extra']['exceptions_in_exception_handler'])) {
                            $context['tags']['exception'] = 'true';
                        }

                        return ['add_context' => $context];
                    }
                ],

san3jaya avatar Sep 01 '21 10:09 san3jaya