Skip to content

Latest commit

 

History

History
69 lines (56 loc) · 1.59 KB

catch-all-to-map-error.md

File metadata and controls

69 lines (56 loc) · 1.59 KB

catchAllToMapError

Suggests using Effect.mapError instead of Effect.catch + Effect.fail

Property Value
Category Style
Default severity suggestion
Fixable Yes
Effect versions v3, v4
Diagnostic codes TS377010
Language Service name catchAllToMapError
Oxlint name effecttsgo/catch-all-to-map-error

Preview

import { Effect } from "effect"

class WrappedError {
  constructor(readonly cause: unknown) {}
}

export const preview = Effect.fail("boom").pipe(
  Effect.catch((cause) => Effect.fail(new WrappedError(cause)))
/**
  ^^^^^^^^^^^^ effecttsgo(catch-all-to-map-error): `Effect.mapError` expresses the same error-type transformation more directly than `Effect.catch` followed by `Effect.fail`.
*/
)

Language Service Configuration

See the Language Service setup guide for installation instructions.

{
  "$schema": "./node_modules/@effect/tsgo/schema.json",
  "compilerOptions": {
    "plugins": [
      {
        "name": "@effect/language-service",
        "diagnosticSeverity": {
          "catchAllToMapError": "warning"
        }
      }
    ]
  }
}

Oxlint Configuration

See the Oxlint setup guide for installation and patching instructions.

{
  "$schema": "./node_modules/@effect/tsgo/oxlint-schema.json",
  "options": {
    "typeAware": true
  },
  "plugins": ["effecttsgo"],
  "rules": {
    "effecttsgo/catch-all-to-map-error": "warn"
  }
}