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

Too few arguments to function Cake\View\Exception\MissingTemplateException::__construct(), 0 passed #521

Closed
jamisonbryant opened this issue Jun 12, 2023 · 4 comments · Fixed by #523
Labels
bug Something isn't working
Milestone

Comments

@jamisonbryant
Copy link
Contributor

Describe the bug
ExceptionResponse.php creates an instance of the thrown exception object (see line 73) so it can do stuff with it. Occasionally, these exception objects require an argument, such as MissingTemplateException. When this required argument is not present, the application crashes.

To Reproduce
Steps to reproduce the behavior: I'm really not sure but I will post the stack trace.

Cake\View\Exception\MissingTemplateException->__construct
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/ExceptionResponse.php:73
SwaggerBake\Lib\Operation\ExceptionResponse->build
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationDocBlock.php:84
SwaggerBake\Lib\Operation\OperationDocBlock->throws
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationDocBlock.php:42
SwaggerBake\Lib\Operation\OperationDocBlock->getOperation
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Operation/OperationFromRouteFactory.php:96
SwaggerBake\Lib\Operation\OperationFromRouteFactory->create
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/OpenApiPathGenerator.php:62
SwaggerBake\Lib\OpenApiPathGenerator->generate
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Swagger.php:66
SwaggerBake\Lib\Swagger->__construct
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/SwaggerFactory.php:40
SwaggerBake\Lib\SwaggerFactory->create
ROOT/vendor/cnizzardini/cakephp-swagger-bake/src/Lib/Service/OpenApiControllerService.php:26
SwaggerBake\Lib\Service\OpenApiControllerService->__construct
[internal]:??

Expected behavior
I should probably not be getting the MTE in the first place, but since I am and it requires an argument, I'd expect Swagger Bake to know how to give it what it needs so the framework doesn't crash.

Attachments
Was going to bin/cake swagger bake and post an updated swagger.json but actually the CLI crashes with the same error...which is super odd I think given that there's no template for the CLI...

Version and Platform (please complete the following information):

  • OS/Platform: macOS Monterey 12.5.1
  • CakePHP: 4.4.14
  • SwaggerBake Version: 2.5.6

Additional context
I'm trying to get PHP8 attributes to work for setting up flexible routes and making sure they also show up in Swagger.

@jamisonbryant
Copy link
Contributor Author

jamisonbryant commented Jun 12, 2023

By reading the stack trace closer I think I have uncovered the problem.

When the OpenApiPathGenerator scans the controller docblock for my PagesController it picks up the several @throws annotations that are put there by default:

/**
 * Displays a view
 *
 * @param string ...$path Path segments.
 *
 * @return \Cake\Http\Response|null
 * @throws \Cake\Http\Exception\ForbiddenException When a directory traversal attempt.
 * @throws \Cake\View\Exception\MissingTemplateException When the view file could not
 *   be found and in debug mode.
 * @throws \Cake\Http\Exception\NotFoundException When the view file could not
 *   be found and not in debug mode.
 * @throws \Cake\View\Exception\MissingTemplateException In debug mode.
 */
#[Route('/pages/*', 'pages:display', resource: false)]
public function display(string ...$path): ?Response
{ ... }

I'm guessing the path scanner tries to instantiate these exceptions as objects, which it cannot do for the MissingTemplateException because it doesn't have the required parameter, thus the crash.

Indeed, if I comment out the @throws lines (there are two) for the MTE the crash disappears.

@cnizzardini
Copy link
Owner

Looks like this needs to be cleaned up: https://github.com/cnizzardini/cakephp-swagger-bake/blob/master/src/Lib/Operation/ExceptionResponse.php#L73

@cnizzardini cnizzardini added the bug Something isn't working label Jun 12, 2023
@cnizzardini cnizzardini added this to the v2.5.7 milestone Jun 12, 2023
@cnizzardini
Copy link
Owner

I will run a manual test before doing a release on this, but probably not today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants