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

[4.x] Laravel Octane fix: GateWatcher handles stack trace caller not found #1128

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Sep 16, 2021

Fixes #1072 & #1122

TLDR: GateWatcher throws an exception because it can't find the PHP source code location that triggered a gate check for an app using Swoole/Laravel Octane.

With config('telescope.watchers.Watchers\GateWatcher.ignore_packages') enabled (the default setting), method getCallerFromStackTrace() returns null because only vendor/laravel/* code is traced through and no app/Http/Controllers/*.php file is reached. Middleware vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authorize.php triggered the gate check and GateWatcher@recordGateCheck() throws an exception attempting to save the Telescope entry for a missing file location.

<tr v-if="slotProps.entry.content.file">
<td class="table-fit font-weight-bold">Location</td>
<td>
{{slotProps.entry.content.file}}:{{slotProps.entry.content.line}}
</td>
</tr>

The UI hides caller file location details if they're not stored in the Telescope entry so set that path to null and prevent this exception.

This provides less details about what triggered gate checks in Octane apps, but the alternative is adding a GateWatcher entry creation fallback to a hardcoded value of Illuminate/Auth/Middleware/Authorize@handle().

Also fix the getCallerFromStackTrace() docblock for @return as method QueryWatcher@recordQuery() already has a conditional for when it returns null .

For an app using Swoole/Laravel Octane and Telescope configured for
`config('telescope.ignore_packages') === true`, method
getCallerFromStackTrace() will return null.

UI file telescope/resources/js/screens/gates/preview.vue will hide
caller file location details if they're not stored in the Telescope
entry so save that path as null.

Also fix the getCallerFromStackTrace() @return docblock as that method
was written before Laravel Octane magic was conjured up.
@taylorotwell taylorotwell merged commit cdc65f1 into laravel:4.x Sep 16, 2021
@derekmd derekmd deleted the fix-gate-watcher-exception-using-laravel-octane branch September 16, 2021 22:25
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

Successfully merging this pull request may close these issues.

getCallerFromStackTrace returns null, if stack has all vendor paths and ignore_packages is true
2 participants