Skip to content

chore: add ESLint no-restricted-imports rule to prevent raw lazyCaptureException usage #914

@sw-factory-automations

Description

@sw-factory-automations

Description

Raw lazyCaptureException from @/lib/capture bypasses error classification, causing transient Supabase errors to be reported at error level in Sentry. This has been the root cause of 13 bugs over the past 3 weeks. Issue #913 fixes the existing 21 call sites, but without a lint rule, new code will continue to use the raw function.

Adding a no-restricted-imports ESLint rule that blocks direct imports of lazyCaptureException from @/lib/capture (with an exception for src/lib/sentry.ts which re-exports it) will catch this at lint time.

Acceptance Criteria

  • eslint.config.mjs includes a no-restricted-imports rule that flags imports of lazyCaptureException from @/lib/capture with a message directing developers to use captureSupabaseError or captureApiError from @/lib/sentry instead
  • The rule allows src/lib/sentry.ts and src/lib/capture.ts to import/export lazyCaptureException (these are the classification wrappers)
  • The rule allows src/app/global-error.tsx and src/components/route-error.tsx to use raw capture (React error boundaries)
  • pnpm lint passes after fix: replace raw lazyCaptureException with captureSupabaseError in 10 component files #913 is merged (no violations in production code)
  • pnpm lint && pnpm typecheck && pnpm test pass

Dependencies

Depends on #913 (replace existing raw calls first, then add the lint rule)

Technical Notes

  • Use ESLint's built-in no-restricted-imports rule with paths config:
    {
      files: ["src/**/*.ts", "src/**/*.tsx"],
      ignorePatterns: ["src/lib/sentry.ts", "src/lib/capture.ts", "src/app/global-error.tsx", "src/components/route-error.tsx"],
      rules: {
        "no-restricted-imports": ["error", {
          paths: [{
            name: "@/lib/capture",
            importNames: ["lazyCaptureException"],
            message: "Use captureSupabaseError or captureApiError from @/lib/sentry instead. Raw lazyCaptureException bypasses error classification."
          }]
        }]
      }
    }
  • The exact ESLint flat config syntax may differ — adapt to the project's eslint.config.mjs format.
  • Reference .agents/conventions.md for error handling patterns.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions