Skip to content

Commit 06fb14e

Browse files
committed
Improve error handling in linting and dead code analysis in react-doctor
- Updated error handling to log messages when linting or dead code analysis fails, providing better debugging information. - Refactored empty diagnostics handling to ensure consistent return types.
1 parent 595ca55 commit 06fb14e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/react-doctor/src/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ export const diagnose = async (
3535
throw new Error("No React dependency found in package.json");
3636
}
3737

38-
const emptyDiagnostics = (): Diagnostic[] => [];
39-
4038
const lintPromise = lint
4139
? runOxlint(
4240
resolvedDirectory,
4341
projectInfo.hasTypeScript,
4442
projectInfo.framework,
4543
projectInfo.hasReactCompiler,
46-
).catch(emptyDiagnostics)
47-
: Promise.resolve(emptyDiagnostics());
44+
).catch((error: unknown) => {
45+
console.error("Lint failed:", error);
46+
return [] as Diagnostic[];
47+
})
48+
: Promise.resolve([] as Diagnostic[]);
4849

4950
const deadCodePromise = deadCode
50-
? runKnip(resolvedDirectory).catch(emptyDiagnostics)
51-
: Promise.resolve(emptyDiagnostics());
51+
? runKnip(resolvedDirectory).catch((error: unknown) => {
52+
console.error("Dead code analysis failed:", error);
53+
return [] as Diagnostic[];
54+
})
55+
: Promise.resolve([] as Diagnostic[]);
5256

5357
const [lintDiagnostics, deadCodeDiagnostics] = await Promise.all([lintPromise, deadCodePromise]);
5458
const diagnostics = [

0 commit comments

Comments
 (0)