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

Function validateErrorCodes

scripts/update_metrics.ts:104–128  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected