Document unreachable code paths in keyToLabels

These were added to as a diagnostic in case the logic turns out to be
broken.  They should not be possible to reach as any value produced by
labelsToKeys will not cause the error conditions to occur.
This commit is contained in:
Hornwitser committed 2026-03-10 02:35:09 +01:00
1 parent 60eb2389a3
commit 76099d2a42
1 file changed
+4
+4
View File
@@ -276,13 +276,16 @@ function keyToLabels(key: string) {
let matchLabel = /([^=]+)="(([^\\"]|\\["n\\])+)"/y; let matchLabel = /([^=]+)="(([^\\"]|\\["n\\])+)"/y;
while (pos < key.length) { while (pos < key.length) {
if (pos !== 0) { if (pos !== 0) {
/* istanbul ignore if */
if (key[pos] !== ",") { if (key[pos] !== ",") {
// Should be unreachable
throw Error(`Expected , at pos ${pos} in "${key}"`); throw Error(`Expected , at pos ${pos} in "${key}"`);
} }
pos += 1; pos += 1;
} }
matchLabel.lastIndex = pos; matchLabel.lastIndex = pos;
const match = matchLabel.exec(key); const match = matchLabel.exec(key);
/* istanbul ignore else */
if (match) { if (match) {
let [, name, value] = match; let [, name, value] = match;
labels.set(name, value labels.set(name, value
@@ -292,6 +295,7 @@ function keyToLabels(key: string) {
); );
pos += match[0].length; pos += match[0].length;
} else { } else {
// Should be unreachable
throw new Error(`Failed to parse label at pos ${pos} in "${key}"`); throw new Error(`Failed to parse label at pos ${pos} in "${key}"`);
} }
} }