Skip to content

Commit

Permalink
Merge remote branch 'weaverryan/kernel_controller_exception_message'
Browse files Browse the repository at this point in the history
* weaverryan/kernel_controller_exception_message:
  [HttpKernel] Making the "no response returned from controller" more explanatory when it's possible that the user forgot a return statement in his/her controller
  • Loading branch information
fabpot committed Mar 27, 2011
2 parents c2579aa + 80c1027 commit 5ebfb30
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Symfony/Component/HttpKernel/HttpKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
}

if (!$response instanceof Response) {
throw new \LogicException(sprintf('The controller must return a response (%s given).', $this->varToString($response)));
$msg = sprintf('The controller must return a response (%s given).', $this->varToString($response));

// the user may have forgotten to return something
if (null === $response) {
$msg .= ' Did you forget to add a return statement somewhere in your controller?';
}
throw new \LogicException($msg);
}
}

Expand Down Expand Up @@ -187,6 +193,10 @@ private function varToString($var)
return '[resource]';
}

if (null === $var) {
return 'null';
}

return str_replace("\n", '', var_export((string) $var, true));
}
}

0 comments on commit 5ebfb30

Please sign in to comment.