Skip to content

Exception on Compiled Closure Routes #996

@LucianMihalache

Description

@LucianMihalache

Scribe version

5.2.1

PHP version

8.4.7

Laravel version

12.16.0

Scribe config

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions