MCPcopy Create free account
hub / github.com/Effect-TS/tsgo / AnalyzeMissingEffectError

Function AnalyzeMissingEffectError

internal/rules/missing_effect_error.go:50–83  ·  view source on GitHub ↗

AnalyzeMissingEffectError finds all relation errors where an Effect has error types that are not handled by the expected type.

(tp *typeparser.TypeParser, c *checker.Checker, sf *ast.SourceFile)

Source from the content-addressed store, hash-verified

48// AnalyzeMissingEffectError finds all relation errors where an Effect has error
49// types that are not handled by the expected type.
50func AnalyzeMissingEffectError(tp *typeparser.TypeParser, c *checker.Checker, sf *ast.SourceFile) []MissingEffectErrorMatch {
51 var matches []MissingEffectErrorMatch
52
53 for _, re := range c.GetRelationErrors(sf) {
54 // Parse both types as Effects
55 srcEffect := tp.EffectType(re.Source)
56 tgtEffect := tp.EffectType(re.Target)
57
58 // Both must be Effect types
59 if srcEffect == nil || tgtEffect == nil {
60 continue
61 }
62
63 // If source has no errors, nothing to report
64 if srcEffect.E.Flags()&checker.TypeFlagsNever != 0 {
65 continue
66 }
67
68 // Find unhandled error types
69 unhandledErrors := findUnhandledErrors(tp, c, srcEffect.E, tgtEffect.E)
70 if len(unhandledErrors) > 0 {
71 matches = append(matches, MissingEffectErrorMatch{
72 SourceFile: sf,
73 Location: scanner.GetErrorRangeForNode(sf, re.ErrorNode),
74 ErrorNode: re.ErrorNode,
75 UnhandledErrors: unhandledErrors,
76 ExpectedErrorType: tgtEffect.E,
77 ErrorTypeStr: formatErrorTypes(c, unhandledErrors),
78 })
79 }
80 }
81
82 return matches
83}
84
85// findUnhandledErrors returns the source error types that are not assignable to the target error type.
86func findUnhandledErrors(tp *typeparser.TypeParser, c *checker.Checker, srcE, tgtE *checker.Type) []*checker.Type {

Callers 2

Calls 3

findUnhandledErrorsFunction · 0.85
formatErrorTypesFunction · 0.85
EffectTypeMethod · 0.45

Tested by

no test coverage detected