{"record":{"id":"6a339f24ca99a9bd","repo":"balderdashy/sails","slug":"e-view-infer","errorCode":"E_VIEW_INFER","errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"lib/hooks/views/res.view.js","lineNumber":153,"sourceCode":"\n    // if (_.isFunction(locals)) {\n    //   optionalCb = locals;\n    //   locals = {};\n    // }\n    // if (_.isFunction(specifiedPath)) {\n    //   optionalCb = specifiedPath;\n    // }\n\n    // If a view path cannot be inferred, send back an error instead\n    if (!relPathToView) {\n      var err = new Error();\n      err.name = 'Error in res.view()';\n      err.code = 'E_VIEW_INFER';\n      err.type = err.code;// <<TODO remove this\n      err.message = 'No path specified, and no path could be inferred from the request context.';\n\n      // Prevent endless recursion:\n      if (req._errorInResView) { return res.sendStatus(500); }\n      req._errorInResView = err;\n\n      if (optionalCb) { return optionalCb(err); }\n      else {return res.serverError(err);}\n    }\n\n\n    // Ensure specifiedPath is a string (important)\n    relPathToView = '' + relPathToView + '';\n\n    // Ensure `locals` is an object\n    locals = _.isObject(locals) ? locals : {};\n\n    // Mixin locals from req.options.\n    // TODO -- replace this _.merge() with a call to the merge-dictionaries module?\n    if (req.options.locals) {\n      locals = _.merge(locals, req.options.locals);\n    }","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/balderdashy/sails/blob/7b76422cc27823df033572bdda5c4910a68b697f/lib/hooks/views/res.view.js#L135-L171","documentation":"E_VIEW_INFER is thrown by Sails' res.view() when no view path is given as an argument and none can be inferred from the request context. res.view() normally derives the view path from the current route's target (controller/action), so this error means the route was bound without enough context to guess a view. Sails then forwards the error to res.serverError() (or an optional callback), producing a 500 response with message 'Internal Server Error'.","triggerScenarios":"Calling res.view() with no arguments inside code reached via a route that has no implicit view target, e.g. a custom standalone response handler, a policy-driven flow, or a route like 'GET /': function(req,res){ res.view(); } where no matching views/<controller>/<action>.ejs path can be guessed.","commonSituations":"Renaming a controller or action so the inferred view path no longer matches; calling res.view() from a route bound to an inline function instead of a Controller.action string; calling res.view() inside custom hooks, blueprints overrides, or shadow routes where no route target exists.","solutions":["Pass the view path explicitly: res.view('pages/mypage') instead of res.view().","Ensure the route target is a controller action (Controller.action string) so res.view() can infer the matching view file.","Create the view file at the path Sails infers (api/views/<controller>/<action>.ejs).","If the response should be JSON only, use res.json() instead of res.view()."],"exampleFix":"// before\n'GET /': function (req, res) {\n  res.view(); // E_VIEW_INFER: no path to infer\n}\n// after\n'GET /': function (req, res) {\n  return res.view('pages/home');\n}","handlingStrategy":"validation","validationCode":"if (typeof viewPath === 'undefined') { /* route target can't infer a view */ return res.json({ error: 'no view' }); }\nreturn res.view(viewPath);","typeGuard":"function hasViewPath(req) { return typeof req.options !== 'undefined' && typeof req.options.view === 'string'; }","tryCatchPattern":"try { return res.view(pathOrUndefined); } catch (e) { if (e && e.code === 'E_VIEW_INFER') { return res.json({ error: 'view path required' }); } throw e; }","preventionTips":["Always pass an explicit path to res.view() when the route target is an inline function.","Keep route targets as Controller.action strings so view inference works.","Name view files to match controller/action conventions."],"tags":["views","routing","sails"],"backgroundTag":"view-path-not-inferred","analyzedSha":"7b76422cc27823df033572bdda5c4910a68b697f","analyzedAt":"2026-09-01T04:01:57.104Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}