slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.94k stars 1.95k forks source link

Fails silently #1910

Closed geggleto closed 8 years ago

geggleto commented 8 years ago

We need to add a check to Route Actions to ensure they are returning a response.

In the event of no returned response a 200 Okay is generated.... we should be raising an exception to aide the developer in debugging.

Example

    $this->post('/create', function (Request $request, Response $response) use ($post) {
        $post->create($request, $response);
        //$post->create returns $response->withRedirect(); ... 200 is generated.
    });

Expected

throw new \Exception("No response returned from callable");

Options

We should provide an additional container key to toggle this functionality on/off.

enforceResponseFromRouteAction

geggleto commented 8 years ago

That's my point :)

if you forget the return it's so stupid hard to debug because no errors are raised ;)

On Wed, Jun 15, 2016 at 4:09 PM, Martijn Wennink notifications@github.com wrote:

Is the code an exact copy? You forgot a return

$this->post('/create', function (Request $request, Response $response) use ($post) {        return $post->create($request, $response);    });

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/slimphp/Slim/issues/1910#issuecomment-226304762, or mute the thread https://github.com/notifications/unsubscribe/AD100ndmAamvwmPPi6XsvBmfjsx5ARUlks5qMFvogaJpZM4I2vJ9 .

JoeBengalen commented 8 years ago

Haha yeah, I reread your post and noticed that. I had already removed it, hoping nobody would notice. Guess I was too late :disappointed:

akrabat commented 8 years ago

Not returning anything is an intentional state. You can turn it off by setting outputBuffering to false.

We should probably warn if we detect that the output buffer is empty and response wasn't returned though.

geggleto commented 8 years ago

@akrabat sounds like a lot of effort, idk i think it can be covered in 4.0