mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 07:24:52 +09:00
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:
1 parent
60eb2389a3
commit
76099d2a42
1 file changed
+4
@@ -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}"`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user