balderdashy/sails · error

rc(name): name *must* be string

Error message

rc(name): name *must* be string

What it means

The `rc` utility used to load Sails configuration requires its first argument, the app name, to be a string. Passing a non-string (undefined, object, number) to rc(name) throws this error immediately.

Source

Thrown at lib/util/rc.js:152

    function find(start, rel) {
      var file = path.join(start, rel);
      try {
        fs.statSync(file);
        return file;
      } catch (unusedErr) {
        if(path.dirname(start) !== start) {// root
          return find(path.dirname(start), rel);
        }
      }
    }
    return find(process.cwd(), rel);
  };



  if('string' !== typeof name) {
    throw new Error('rc(name): name *must* be string');
  }
  if(!argv) {
    argv = require('minimist')(process.argv.slice(2));
  }
  defaults = (
      'string' === typeof defaults
    ? jsonFn(defaults) : defaults
  ) || {};

  parse = parse || parseFn;

  var env = envFn(name + '_');

  var configs = [defaults];
  var configFiles = [];
  function addConfigFile (file) {
    if (configFiles.indexOf(file) >= 0) {return;}
    var fileConfig = fileFn(file);

View on GitHub (pinned to 7b76422cc2)

Solutions

  1. Pass a non-empty string as the first argument, e.g. `rc('sails', { ... })`.
  2. Check argument order when calling rc; the name must come before defaults/argv.
  3. If name comes from variables, validate with typeof name === 'string' before calling.
  4. Use require('rc') from the same version Sails expects to avoid signature drift.

Example fix

// before
var config = rc();
// after
var config = rc('sails');
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof name !== 'string' || !name.length) { throw new TypeError('rc(name): name must be a non-empty string'); }

Type guard

function isRcName(v) { return typeof v === 'string' && v.length > 0; }

Try / catch

try { config = rc(name); } catch (e) { if (/name \*must\* be string/.test(e.message)) { config = rc('sails'); } else { throw e; } }

Prevention

When it happens

Trigger: Calling rc(name) with `name` undefined, null, a number, or an object; programmatically loading Sails config with `require('sails').load()`-style helpers that pass a bad name; calling the rc module directly with missing args.

Common situations: Custom config loaders wiring rc() incorrectly; calling rc() with arguments in the wrong order; forgetting the app name parameter entirely.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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