scribe icon indicating copy to clipboard operation
scribe copied to clipboard

Exceptions during Model factory creation for API endpoints are never printed -- no matter verbose setting

Open dlebech opened this issue 1 year ago • 1 comments

Scribe version

4.37.0

PHP version

8.2

Framework

Laravel

Framework version

11.12.0

Scribe config

title => "API Documentation"
auth.name => "Authorization"
strategies.responses => added [
    'Knuckles\\Scribe\\Extracting\\Strategies\\Responses\\ResponseCalls',
    [
        'only' => [
            'GET *',
        ],
    ],
]: removed [
    'Knuckles\\Scribe\\Extracting\\Strategies\\Responses\\ResponseCalls',
    [
        'only' => [
            'GET *',
        ],
        'config' => [
            'app.debug' => false,
        ],
    ],
]

What happened?

Reproduce

  • I run php artisan scribe:generate -vvv (or php artisan scribe:generate --verbose)
  • I see some warnings for my models like "Couldn't get example model App\Model[modelname] via factoryCreate
  • I expected to see exception output (and stack trace) for each of these warnings, so I can debug the issue, but I only get the warning.

Explanation/analysis

The reason there is no exception output is that $completelySilent parameter for the function dumpExceptionIfVerbose is always set to true in the model factory exception handler: https://github.com/knuckleswtf/scribe/blob/3ab4ae7029b3db58b5509e3721b2dc146f04a17e/src/Extracting/InstantiatesExampleModels.php#L56

Possible fix

I would expect that the parameter $completelySilent should either be absent or false in the code mentioned above. When I go to the vendor/ source and change that line to false, I get the stacktrace and exception output as expected.

I can submit a PR for this, if you agree with my analysis.

Docs

dlebech avatar Sep 16 '24 09:09 dlebech

Yeah, I think the reason for that was to limit noise, since model instantiation was not very customizable in the past. But you're correct, this shouldn't swallow exceptions. PR welcome 👍

shalvah avatar Sep 17 '24 12:09 shalvah

@brianferri 🎉 🏆 Thank you

I got completely sidetracked with other work and forgot about this one 🙈

dlebech avatar Mar 04 '25 13:03 dlebech