diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2022-01-02 10:56:25 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2022-01-02 10:56:47 -0400 |
commit | c2428d2a136d2af4ed7235240308082db32cb3f8 (patch) | |
tree | 4b9f3503b8891fcbd164eb3d6f5ba1f6673dd429 | |
parent | 2db6ae3236fba513e33a2f594dcc1aa405881f02 (diff) |
fix missing args errors not being thrown from to()
-rw-r--r-- | src/util/urls.js | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/util/urls.js b/src/util/urls.js index 12a1651f..a30cc81b 100644 --- a/src/util/urls.js +++ b/src/util/urls.js @@ -69,16 +69,20 @@ export function generateURLs(urlSpec) { const toHelper = (delimiterMode) => (key, ...args) => { const { - value: {[delimiterMode]: template}, - group: {[groupSymbol]: toGroup} + value: {[delimiterMode]: template} } = getValueForFullKey(relative, key); - let result = template.replaceAll(/<([0-9]+)>/g, (match, n) => args[n]); + let missing = 0; + let result = template.replaceAll(/<([0-9]+)>/g, (match, n) => { + if (n < args.length) { + return args[n]; + } else { + missing++; + } + }); - // Kinda hacky lol, 8ut it works. - const missing = result.match(/<([0-9]+)>/g); if (missing) { - throw new Error(`Expected ${missing[missing.length - 1]} arguments, got ${args.length}`); + throw new Error(`Expected ${missing + args.length} arguments, got ${args.length} (key ${key}, args [${args}])`); } return result; |