From 6191afe08f6c2bebdf2ee6faf95437bc078ace8e Mon Sep 17 00:00:00 2001 From: Jordan Lees Date: Mon, 7 Apr 2025 01:15:01 -0400 Subject: [PATCH] Add a helpful error message when pathRegexp fails --- lib/layer.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/layer.js b/lib/layer.js index 6a4408f..198c929 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -83,12 +83,18 @@ function Layer (path, options, fn) { } } - return pathRegexp.match((opts.strict ? _path : loosen(_path)), { - sensitive: opts.sensitive, - end: opts.end, - trailing: !opts.strict, - decode: decodeParam - }) + try { + return pathRegexp.match((opts.strict ? _path : loosen(_path)), { + sensitive: opts.sensitive, + end: opts.end, + trailing: !opts.strict, + decode: decodeParam + }); + } + catch (err) { + console.error(err); + throw new Error(`The path route '${_path}' could not be parsed. Check the above error message for details.`); + } } this.matchers = Array.isArray(path) ? path.map(matcher) : [matcher(path)] }