From 76099d2a42b29e1ba42e3e155c0eb0b23b552343 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Tue, 10 Mar 2026 02:24:03 +0100 Subject: [PATCH] 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. --- packages/lib/src/prometheus.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/lib/src/prometheus.ts b/packages/lib/src/prometheus.ts index becdf0cb..84999093 100644 --- a/packages/lib/src/prometheus.ts +++ b/packages/lib/src/prometheus.ts @@ -276,13 +276,16 @@ function keyToLabels(key: string) { let matchLabel = /([^=]+)="(([^\\"]|\\["n\\])+)"/y; while (pos < key.length) { if (pos !== 0) { + /* istanbul ignore if */ if (key[pos] !== ",") { + // Should be unreachable throw Error(`Expected , at pos ${pos} in "${key}"`); } pos += 1; } matchLabel.lastIndex = pos; const match = matchLabel.exec(key); + /* istanbul ignore else */ if (match) { let [, name, value] = match; labels.set(name, value @@ -292,6 +295,7 @@ function keyToLabels(key: string) { ); pos += match[0].length; } else { + // Should be unreachable throw new Error(`Failed to parse label at pos ${pos} in "${key}"`); } }