microsoft / microsoft/TypeScript

Feature: Analyze @throws tags

Aperta
#31,329 12 commenti 55 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Description

Given a function has a @throws JSDoc tag, it would be helpful to apply some analysis and raise a compiler warning (or, if configured, an error) when the caller does not handle the error and it doesn't declare its own @throws tag.

Examples
/**
 * @throws {SomeException}
 */
function myFunction() {
  // some logic
  // then for some reason we throw an exception
  if (somethingWentWrong) {
    throw new SomeException("something happened");
  }
  // some more logic
}

function potentialMess() {
  myFunction(); // Compiler error: 'myFunction' may throw `SomeException`. ts(9876)
}

/**
 * @throws {SomeException}
 */
function letItBubble() {
  myFunction(); // No compiler errors
}

function aFunctionThatHandlesTheException() {
  try {
    myFunction(); // No compiler errors
  }
  catch (error) {
    // do something with the error
  }
}
Questions
  • Ideally, it would be even better if VSCode realizes that myFunction throws an error, and then @throws is not required for the analysis. Still, this approach would be useful when dealing with external code/interfaces.

  • It is my understanding that JSDoc's @throws is allowed once -- if this is correct, then VSCode could ignore this and accept multiple tags anyway? Otherwise, maybe we can use a different tag, e.g. @exception?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Parti dagli esempi JSDoc @throws dell'issue e segui il modo in cui il compilatore TypeScript gestisce le chiamate, gli errori lanciati e il flusso di controllo di try/catch. Definisci come completamento la presenza di avvisi o errori configurabili per le chiamate non gestite, la propagazione quando il chiamante dichiara @throws e nessuna diagnostica quando l'eccezione viene catturata; le domande sugli inferred throws e sui tag ripetuti richiedono decisioni di progettazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.