mattpocock / ts-error-translator

VSCode extension to turn TypeScript errors into plain English
https://ts-error-translator.vercel.app
2.36k stars 90 forks source link

Error: Cannot read properties of undefined (reading 'filter') #264

Open felixhaeberle opened 6 months ago

felixhaeberle commented 6 months ago

Description

Encountered an unhandled TypeError during the execution of updateDiagnostics function in the TypeScript error translator extension for VSCode. The error suggests an issue with reading properties of an undefined object, specifically when attempting to filter diagnostics.

Error Details

Stack Trace

TypeError: Cannot read properties of undefined (reading 'filter')
    at /Users/jobayerhossain/.vscode/extensions/mattpocock.ts-error-translator-0.10.1/out/extension.js:61730:36

Code Snippet

try {
  // Existing code that might throw an error
} catch (e) {
  // Error handling
}
helperDiagnostics.set(
  document2.uri,
  uriStore[document2.uri.path].filter(tipHasNoDepsOrAllDepsCompleted).filter((tip) => !isTipComplete(tip.type)).map((tip) => {
    const diagnostic = new vscode5.Diagnostic(
      tip.range,
      tip.type,
      vscode5.DiagnosticSeverity.Information
    );
    diagnostic.source = "total-typescript";
    return diagnostic;
  })
);

Potential Issue

The error appears to be related to the assumption that uriStore[document2.uri.path] is always defined and can be filtered. This may not be the case, leading to the TypeError when attempting to call .filter() on an undefined object.

Steps to Reproduce

  1. Install the TypeScript error translator extension (version 0.10.1) in VSCode.
  2. Trigger the updateDiagnostics function under conditions that lead to uriStore[document2.uri.path] being undefined.

Expected Behavior

updateDiagnostics should handle cases where uriStore[document2.uri.path] is undefined, avoiding any TypeErrors related to calling .filter() on undefined.

Actual Behavior

The application throws a TypeError when it attempts to filter on an undefined object within the updateDiagnostics function.

Environment

Bildschirmfoto 2024-02-08 um 10 31 37