MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / validateErrorCodes

Function validateErrorCodes

scripts/update_metrics.ts:108–132  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

106}
107
108function validateErrorCodes(): void {
109 // The compiled JavaScript object has both forward and backward mappings of the enum,
110 // for example: { '0': 'ERROR_CODE_UNSPECIFIED', 'ERROR_CODE_UNSPECIFIED': 0 }.
111 // This filters out the numeric keys.
112 const stringKeysOnly = Object.entries(ErrorCode).filter(([key]) =>
113 isNaN(Number(key)),
114 );
115
116 let expectedIndex = 0;
117 for (const [key, index] of stringKeysOnly) {
118 if (index !== expectedIndex) {
119 throw new Error(
120 `Error: ErrorCode enums must be sequentially numbered from 0.`,
121 );
122 }
123 if (/_\d/.test(key)) {
124 throw new Error(
125 `Error: ErrorCode enum ${key} is invalid. No numbers should be preceded with an underscore.`,
126 );
127 }
128 expectedIndex++;
129 }
130
131 console.log(`Successfully validated ${expectedIndex} ErrorCode enums.`);
132}
133
134function main() {
135 validateErrorCodes();

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected