Skip to content

Commit 70f193a

Browse files
committed
fix(tests): noisy console.error() messages
Problem: When parsing fails, it logs redundant errors and then throws an exception. This is pointless and redundant because the exception can carry the same info and anything showing the console output will also show the error message. And the console.error() calls add lots of noise to *successful* test results (for tests that *expect* validation to fail): console.error Error while trying to parse the definitions file /not/a/real/path: {} 55 | return input as MetricDefinitionRoot 56 | } catch (errors) { > 57 | console.error(`Error while trying to parse the definitions file ${fileName}: ${JSON.stringify(errors)}`) | ^ 58 | throw new Error('Failed to parse') 59 | } 60 | } at validateInput (src/parser.ts:57:17) at test/parser.test.ts:19:35 at Object.<anonymous> (node_modules/expect/build/toThrowMatchers.js:74:11) at Object.throwingMatcher [as toThrowError] (node_modules/expect/build/index.js:320:21) at Object.<anonymous> (test/parser.test.ts:19:64) ...[many more] Solution: Remove the console.error() calls.
1 parent 5ca6300 commit 70f193a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

telemetry/vscode/src/parser.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ export function validateInput(fileText: string, fileName: string): MetricDefinit
4949
const input = JSON.parse(fileText)
5050
const valid = jsonValidator(input)
5151
if (!valid) {
52-
console.error('validating schema failed!')
5352
throw jsonValidator.errors
5453
}
5554
return input as MetricDefinitionRoot
5655
} catch (errors) {
57-
console.error(`Error while trying to parse the definitions file ${fileName}: ${JSON.stringify(errors)}`)
58-
throw new Error('Failed to parse')
56+
const msg = `Failed to parse definitions file ${fileName}: ${JSON.stringify(errors)}`
57+
throw new Error(msg)
5958
}
6059
}

0 commit comments

Comments
 (0)