balderdashy/sails · warning
Invalid regex "${regex}" supplied to skipRegexesWrapper; ign
Error message
Invalid regex "${regex}" supplied to skipRegexesWrapper; ignoring. What it means
`skipRegexesWrapper` wraps route handling with regex-based skip logic. Every value in the regexes array must be a real RegExp instance; any non-RegExp entry is dropped and this warning is logged, so that path pattern silently won't be skipped.
Source
Thrown at lib/router/bind.js:437
};
};
/**
* Wrap a route in a helper function that first checks whether the URL matches
* any of a set of regexes, and if so, skips the defined handler.
*
* @param {array} regexes Array of regexes to match the URL against
* @param {Function} fn Middleware function to run if URL does NOT match regexes
* @return {Function} A middleware function
*/
var skipRegexesWrapper = function(regexes, fn) {
// Remove anything that's not a regex
regexes = _.compact(regexes.map(function(regex) {
if (regex instanceof RegExp) {
return regex;
}
sails.log.warn('Invalid regex "' + regex + '" supplied to skipRegexesWrapper; ignoring.');
return undefined;
}));
return function(req, res, next) {
// Check for matches
for (var i = 0; i < regexes.length; i++) {
if (req.url.match(regexes[i])) {
// If we find one, bail out
return next();
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: Need to double-check on this, but shouldn't this call `enhancedFn`, instead of just `fn`?
// If so, then we can just make that change. Otherwise, we need to do more here.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -View on GitHub (pinned to 7b76422cc2)
Solutions
- Use RegExp literals instead of strings: `/^\/api\//` instead of `'/^\/api\//'`
- Remove the invalid entries if skipping is not needed
- Convert string patterns with `new RegExp(pattern)` at config definition
Example fix
// before skipRegexes: ['^/api/'] // after skipRegexes: [/^\/api\//]
Defensive patterns
Strategy: type-guard
Validate before calling
function assertRegexes(arr) {
arr.forEach(v => { if (!(v instanceof RegExp)) throw new TypeError('skipRegexes entries must be RegExp: ' + v); });
} Type guard
function isRegExpArray(v) {
return Array.isArray(v) && v.every(x => x instanceof RegExp);
} Prevention
- Always write skip patterns as /.../ RegExp literals, never strings
- Convert string patterns with new RegExp(s) if config comes from JSON/env
- Add a startup validation for policy/middleware config
When it happens
Trigger: Passing strings (e.g. `'/^\/api/'`) or other non-RegExp values into a skipRegexes config or policy option that feeds `skipRegexesWrapper`.
Common situations: Configuring skip patterns as strings in config/policies.js or custom middleware instead of RegExp literals — a common mistake since routes elsewhere use strings.
Related errors
- E_VIEW_INFER
- The session middleware encountered an error and triggered it
- Ignored attempt to bind route (${path}) to unknown action ::
- Warning: route `${address}` should explicitly declare `skipA
- See http://sailsjs.com/docs/concepts/routes/url-slugs for mo
AI-assisted analysis of balderdashy/sails@7b76422cc2 (2026-09-01).
Data as JSON: /api/errors/1f9afe92a094c540.
Report an issue: GitHub.