microsoft / microsoft/TypeScript
Feature: Analyze @throws tags
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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
myFunctionthrows an error, and then@throwsis not required for the analysis. Still, this approach would be useful when dealing with external code/interfaces. -
It is my understanding that JSDoc's
@throwsis 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?
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den JSDoc-@throws-Beispielen des Issues und verfolge, wie der TypeScript-Compiler Aufrufe, ausgelöste Fehler und den Kontrollfluss von try/catch behandelt. Definiere den Abschluss als Warnungen oder konfigurierbare Fehler für nicht behandelte Aufrufe, Weitergabe, wenn der Aufrufer @throws deklariert, und keine Diagnose, wenn die Ausnahme abgefangen wird; die Fragen zu inferred throws und wiederholten Tags erfordern Designentscheidungen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100