knuckleswtf / knuckleswtf/scribe

Exception on Compiled Closure Routes

Open
#996 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
2.3k
Forks
357
PR merge metrics
No merged PRs in 30d

Description

### Scribe version

5.2.1

### PHP version

8.4.7

### Laravel version

12.16.0

### Scribe config

```ruby
Does not matter in this case
```

### What happened?

If you have a closure route:
`
Route::get('/test', function () {
return response()->json([]);
});
`
And run laravel's optimization: `php artisan optimize`
Then run scribe's generation: `php artisan scribe:generate`
Throws error because scribe is trying to look for a controller and an action to look into it.

```
local.ERROR: Unable to retrieve controller and method for route; try running `php artisan route:clear` {"exception":"[object] (Knuckles\\Scribe\\Exceptions\\CouldntGetRouteDetails(code: 0): Unable to retrieve controller and method for route; try running `php artisan route:clear` at /var/www/vendor/knuckleswtf/scribe/src/Exceptions/CouldntGetRouteDetails.php:9)
[stacktrace]
#0 /var/www/vendor/knuckleswtf/scribe/src/Tools/Utils.php(98): Knuckles\\Scribe\\Exceptions\\CouldntGetRouteDetails::new()
#1 /var/www/vendor/knuckleswtf/scribe/src/GroupedEndpoints/GroupedEndpointsFromApp.php(107): Knuckles\\Scribe\\Tools\\Utils::getRouteClassAndMethodNames()
#2 /var/www/vendor/knuckleswtf/scribe/src/GroupedEndpoints/GroupedEndpointsFromApp.php(72): Knuckles\\Scribe\\GroupedEndpoints\\GroupedEndpointsFromApp->extractEndpointsInfoFromLaravelApp()
#3 /var/www/vendor/knuckleswtf/scribe/src/GroupedEndpoints/GroupedEndpointsFromApp.php(50): Knuckles\\Scribe\\GroupedEndpoints\\GroupedEndpointsFromApp->extractEndpointsInfoAndWriteToDisk()
#4 /var/www/vendor/knuckleswtf/scribe/src/Commands/GenerateDocumentation.php(55): Knuckles\\Scribe\\GroupedEndpoints\\GroupedEndpointsFromApp->get()
#5 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Knuckles\\Scribe\\Commands\\GenerateDocumentation->handle()
#6 /var/www/vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\\Container\\BoundMethod::{closure:Illuminate\\Container\\BoundMethod::call():35}()
#7 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(96): Illuminate\\Container\\Util::unwrapIfClosure()
#8 /var/www/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#9 /var/www/vendor/laravel/framework/src/Illuminate/Container/Container.php(754): Illuminate\\Container\\BoundMethod::call()
#10 /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(211): Illuminate\\Container\\Container->call()
#11 /var/www/vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute()
#12 /var/www/vendor/laravel/framework/src/Illuminate/Console/Command.php(180): Symfony\\Component\\Console\\Command\\Command->run()
#13 /var/www/vendor/symfony/console/Application.php(1094): Illuminate\\Console\\Command->run()
#14 /var/www/vendor/symfony/console/Application.php(342): Symfony\\Component\\Console\\Application->doRunCommand()
#15 /var/www/vendor/symfony/console/Application.php(193): Symfony\\Component\\Console\\Application->doRun()
#16 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(197): Symfony\\Component\\Console\\Application->run()
#17 /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1234): Illuminate\\Foundation\\Console\\Kernel->handle()
#18 /var/www/artisan(16): Illuminate\\Foundation\\Application->handleCommand()
#19 {main}
"}
```

The issue is here: `Knuckles\Scribe\Tools\Utils::getRouteClassAndMethodNames()`
It checks only for normal routes. It does not know about closure routes.
I know its an edge case, but still.

### Docs

- [x] I've checked [the docs](https://scribe.knuckles.wtf/laravel), the [troubleshooting guide](https://scribe.knuckles.wtf/laravel/troubleshooting), and [existing issues](https://github.com/knuckleswtf/scribe/issues?q=is%3Aissue+), but I didn't find a solution

Contributor guide

Open the contributing guide

Research direction

Start in src/Tools/Utils.php at getRouteClassAndMethodNames(), then trace how GroupedEndpointsFromApp uses its result during scribe:generate. Reproduce with a closure route after php artisan optimize and confirm that generation no longer throws CouldntGetRouteDetails for that route.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.