Always ensure errors are properly surfaced rather than silently ignored. Silent error handling can lead to confusing behavior where features fail without any indication of what went wrong, making debugging difficult or impossible.
Always ensure errors are properly surfaced rather than silently ignored. Silent error handling can lead to confusing behavior where features fail without any indication of what went wrong, making debugging difficult or impossible.
There are several ways to properly handle errors instead of silently swallowing them:
// Good
try {
await this.findTestFiles();
} catch (error) {
this.outputChannel.appendLine(Test discovery failed: ${error.message}
);
}
2. Maintain important assertions that validate input requirements:
```typescript
// Bad
export function isReadableStreamLocked(stream) {
// $assert($isReadableStream(stream)); // Don't remove assertions!
}
// Good
export function isReadableStreamLocked(stream) {
$assert($isReadableStream(stream));
}
// Good
const initResult = handle.init(initParamsArray, pledgedSrcSize, writeState, processCallback);
if (initResult !== 0) {
throw new Error(Initialization failed with code ${initResult}
);
}
```
When errors are properly surfaced, developers can identify and fix issues more efficiently, leading to more robust and maintainable code.
Enter the URL of a public GitHub repository