balderdashy/sails · warning

`res.guessView()` is deprecated in Sails >= v1.0. If you wa

Error message

`res.guessView()` is deprecated in Sails >= v1.0.  If you want to continue to use it
in your Sails app, please just drop its implementation into a hook.
 [?] Unsure or need advice?  Stop by https://sailsjs.com/support

What it means

`res.guessView()` was removed as a first-class API in Sails v1.0. Calling it now logs this deprecation warning but still works temporarily by delegating to `res.view()` with a guessed path. The supported path is to implement the guessing logic yourself inside a custom hook.

Source

Thrown at lib/hooks/views/res.view.js:46

  // ```
  // function (req,res,next) { _addResViewMethod(req,res); next(); }
  // ```
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



  /**
   * res.guessView([locals], [couldNotGuessCb])
   *
   * @param  {Object} locals
   * @param  {Function} couldNotGuessCb
   */
  res.guessView = function (locals, couldNotGuessCb) {

    // - - - - - - - - - - - - - - - - - - - - - - - - - - -
    // FUTURE: Completely remove res.guessView()
    // - - - - - - - - - - - - - - - - - - - - - - - - - - -
    sails.log.warn(
      '`res.guessView()` is deprecated in Sails >= v1.0.  If you want to continue to use it\n'+
      'in your Sails app, please just drop its implementation into a hook.\n'+
      ' [?] Unsure or need advice?  Stop by https://sailsjs.com/support'
    );

    return res.view(locals, function viewReady(err, html) {

      // If this is an "implied view doesn't exist" error,
      // just serve JSON instead.
      if (err && (err.code === 'E_VIEW_INFER' || err.code === 'E_VIEW_FAILED')) {
        return (couldNotGuessCb||res.serverError)(err);
      }

      // But if some other sort of error occurred, call `res.serverError`
      else if (err) {return res.serverError(err);}

      // Otherwise we're good, serve the view
      return res.send(html);

View on GitHub (pinned to 7b76422cc2)

Solutions

  1. Replace `res.guessView()` with explicit `res.view(path, locals)` calls
  2. Move the guessView implementation into a custom hook that attaches it to res
  3. Remove the call if unused

Example fix

// before
res.guessView(locals, function(err, html) { ... });
// after
res.view('homepage', locals, function(err, html) { ... });
Defensive patterns

Strategy: fallback

Validate before calling

if (typeof res.guessView === 'function' && !res.guessView.__warned) {
  console.warn('res.guessView is deprecated; migrate to res.view(path, locals)');
}

Try / catch

try {
  res.guessView(locals, cb);
} catch (err) {
  res.view('fallback-view', locals, cb); // supported API fallback
}

Prevention

When it happens

Trigger: Any request handler or policy calling `res.guessView(locals, cb)` in a Sails >= 1.0 app, typically code upgraded from 0.12.

Common situations: Legacy 0.12 apps lifted on Sails 1.x after `sails lift` migration; old error-handling code that guessed view paths based on request headers.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of balderdashy/sails@7b76422cc2 (2026-09-01). Data as JSON: /api/errors/ccd9611721737539. Report an issue: GitHub.