warnNullMiddleware function

void warnNullMiddleware(
  1. Object middleware,
  2. RouteData route
)

in development (APP_ENV is development or local), write a warning once per middleware that gives null. null ends the request with an empty 200, and the controller never runs. Most of the time the middleware forgot return req. Nothing else changes.

Implementation

void warnNullMiddleware(Object middleware, RouteData route) {
  if (!(_warnNullOn ??= _isDevelopment())) return;
  if (!_warnedNull.add(middleware)) return;
  String name = middleware is Function
      ? 'A middleware function'
      : '${middleware.runtimeType}';
  // stderr, not Logger: the logger is off by default
  stderr.writeln(
    'dox: warning: $name on ${route.method} ${route.path} returned null, '
    'so the request ended with an empty 200 and the controller did not '
    'run. Return the request (return req) to go on, or return a response.',
  );
}