Skip to content

Commit 9ef21c2

Browse files
authored
Merge pull request #43 from estyemma/console
Updated: Improve Console Logging Strategy
2 parents 4a5bae7 + cccd7fb commit 9ef21c2

33 files changed

+10355
-168
lines changed

TODO.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Fix ESLint Errors Plan
2+
3+
## Files to Edit
4+
5+
### 1. src/app/api/errors/route.ts ✅
6+
- Change import { NextRequest, NextResponse } to import type { NextRequest } and import { NextResponse }
7+
- Change import { ErrorReportingData } to import type { ErrorReportingData }
8+
9+
### 2. src/components/error/ARErrorBoundary.tsx ✅
10+
- Change import React, { Component, ReactNode } to import type { ReactNode }
11+
- Change import { AppError, ErrorBoundaryState, ErrorRecoveryAction } to import type { AppError, ErrorBoundaryState } and import { ErrorRecoveryAction }
12+
- Change "ar" as any to ErrorCategory.AR
13+
- Change errorInfo: any to errorInfo: React.ErrorInfo
14+
15+
### 3. src/components/error/ErrorTestSuite.tsx ✅
16+
- Change recoveryAction: 'reconnect' as any to ErrorRecoveryAction.RECONNECT
17+
- Change other recoveryAction strings to enum values
18+
- Change catch (error: any) to error: unknown
19+
20+
### 4. src/store/base.ts ✅
21+
- Change import { PersistOptions } to import type { PersistOptions }
22+
- Change any to unknown in function parameters and catch
23+
24+
### 5. src/store/debug.ts ✅
25+
- Change all any to unknown or Record<string, unknown> in interfaces and functions
26+
27+
### 6. src/types/errors.ts ✅
28+
- Change Record<string, any> to Record<string, unknown>
29+
30+
### 7. src/utils/errorFactory.ts ✅
31+
- Change imports to import type
32+
- Change any to unknown in error parameters
33+
34+
### 8. src/utils/errorReporting.ts ✅
35+
- Change imports to import type
36+
37+
### 9. src/utils/i18nFormatting.ts ✅
38+
- Change Record<string, any> to Record<string, unknown>

pnpm-lock.yaml

Lines changed: 9539 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/api/errors/route.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { NextRequest, NextResponse } from 'next/server';
2-
import { ErrorReportingData } from '@/types/errors';
1+
import type { NextRequest } from 'next/server';
2+
import { NextResponse } from 'next/server';
3+
import type { ErrorReportingData } from '@/types/errors';
4+
import { logger } from '@/utils/logger';
35

46
export async function POST(request: NextRequest) {
57
try {
@@ -14,7 +16,7 @@ export async function POST(request: NextRequest) {
1416
}
1517

1618
// Log error (in production, this would go to your analytics service)
17-
console.error('Error Report:', {
19+
logger.error('Error Report:', {
1820
id: body.errorId,
1921
category: body.category,
2022
severity: body.severity,
@@ -37,7 +39,7 @@ export async function POST(request: NextRequest) {
3739
);
3840

3941
} catch (error) {
40-
console.error('Error reporting failed:', error);
42+
logger.error('Error reporting failed:', error);
4143
return NextResponse.json(
4244
{ error: 'Internal server error' },
4345
{ status: 500 }

src/app/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ManualErrorSuppressor,
1414
globalErrorSuppressor,
1515
} from "@/utils/manualErrorSuppressor";
16+
import { logger } from "@/utils/logger";
1617
import { WalletConnector } from "@/components/WalletConnector";
1718
import { LanguageSwitcher } from "@/components/LanguageSwitcher";
1819
import {
@@ -39,13 +40,12 @@ function HomeContent() {
3940

4041
// Make manual suppressor available globally
4142
window.suppressErrors = () => {
42-
console.clear();
43-
console.log("🔧 Manual error suppression activated");
43+
logger.info('Manual error suppression activated');
4444
};
4545
}, []);
4646

4747
const handleSampleTransaction = async () => {
48-
console.log("Sample transaction executed");
48+
logger.info('Sample transaction executed');
4949
};
5050

5151
return (

src/components/ChainAwareProps.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React from 'react';
44
import { useChain } from '@/providers/ChainAwareProvider';
55
import { useWalletStore } from '@/store/walletStore';
6+
import { logger } from '@/utils/logger';
67

78
interface ChainAwareProps {
89
children: (props: {
@@ -133,7 +134,7 @@ export const TransactionButton: React.FC<TransactionButtonProps> = ({
133134
try {
134135
await onTransaction();
135136
} catch (error) {
136-
console.error('Transaction failed:', error);
137+
logger.error('Transaction failed:', error);
137138
} finally {
138139
setIsPending(false);
139140
}

src/components/ClientProviders.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
import { WagmiProvider } from "wagmi";
44
import { config } from "@/config/wagmi";
55
import { ChainAwareProvider } from "@/providers/ChainAwareProvider";
6-
import { TransactionMonitor } from "@/components/TransactionMonitor";
7-
import { NotificationSystem } from "@/components/NotificationSystem";
8-
import { Toaster } from "@/components/ui/sonner";
6+
import { PerformanceMonitor } from "@/components/PerformanceMonitor";
97
import "@/lib/i18n";
108
import dynamic from "next/dynamic";
11-
import { WagmiProvider } from 'wagmi';
12-
import { config } from '@/config/wagmi';
13-
import { ChainAwareProvider } from '@/providers/ChainAwareProvider';
14-
import { PerformanceMonitor } from "@/components/PerformanceMonitor";
159

1610
interface ClientProvidersProps {
1711
children: React.ReactNode;

src/components/ErrorBoundary.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
"use client";
22

3-
import React, { Component, ReactNode } from "react";
3+
import React, { Component } from "react";
4+
import type { ReactNode, ErrorInfo } from "react";
45
import {
56
EnhancedErrorBoundary,
67
ErrorBoundaryPresets,
78
} from "./error/EnhancedErrorBoundary";
8-
import { AppError, ErrorCategory } from "@/types/errors";
9+
import type { AppError } from "@/types/errors";
10+
import { ErrorCategory } from "@/types/errors";
911
import { getWalletErrorMessage } from "@/utils/errorHandling";
12+
import { logger } from "@/utils/logger";
13+
import { ErrorFactory } from "@/utils/errorFactory";
1014

1115
interface Props {
1216
children: ReactNode;
@@ -33,11 +37,11 @@ export class ErrorBoundary extends Component<Props, State> {
3337
}
3438

3539
static getDerivedStateFromError(error: Error): Partial<State> {
36-
return { hasError: true, error };
40+
return { hasError: true, error: ErrorFactory.fromError(error, ErrorCategory.UI) };
3741
}
3842

39-
componentDidCatch(error: Error, errorInfo: React.ComponentDidCatchInfo) {
40-
console.error("ErrorBoundary caught an error:", error, errorInfo);
43+
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
44+
logger.error("ErrorBoundary caught an error:", { error, errorInfo });
4145
}
4246

4347
render() {

src/components/PerformanceMonitor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getRating(name: string, value: number): "good" | "needs-improvement" |
1818
return "needs-improvement";
1919
}
2020

21-
export function PerformanceMonitor() {
21+
export function PerformanceMonitor(): React.ReactElement | null {
2222
const addMetric = usePerformanceStore((state) => state.addMetric);
2323

2424
useReportWebVitals((metric) => {
@@ -78,6 +78,8 @@ export function PerformanceMonitor() {
7878
resourceObserver.disconnect();
7979
};
8080
}
81+
82+
return;
8183
}, [addMetric]);
8284

8385
return null;

src/components/PropertySearch.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { useState, useRef, useEffect } from 'react';
44
import { useDebounce } from '@/hooks/useDebounce';
55
import { propertyService } from '@/lib/propertyService';
66
import type { AutocompleteResult } from '@/types/property';
7+
import { logger } from '@/utils/logger';
78

89
interface PropertySearchProps {
910
value: string;
@@ -57,7 +58,7 @@ export const PropertySearch: React.FC<PropertySearchProps> = ({
5758
const results = await propertyService.getAutocompleteSuggestions(query);
5859
setSuggestions(results);
5960
} catch (error) {
60-
console.error('Failed to fetch suggestions:', error);
61+
logger.error('Failed to fetch suggestions:', error);
6162
setSuggestions([]);
6263
} finally {
6364
setIsLoading(false);

src/components/WalletConnector.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React, { useState, useEffect } from 'react';
44
import dynamic from "next/dynamic";
55
import { useWalletStore } from '@/store/walletStore';
66
import { useChain } from '@/providers/ChainAwareProvider';
7+
import { logger } from '@/utils/logger';
78

89
const WalletModal = dynamic(
910
() => import("./WalletModal").then((m) => m.WalletModal),
@@ -50,7 +51,7 @@ export const WalletConnector: React.FC = () => {
5051
setBalance(balanceInEth.toFixed(4));
5152
}
5253
} catch (error) {
53-
console.error('Failed to fetch balance:', error);
54+
logger.error('Failed to fetch balance:', error);
5455
}
5556
};
5657

0 commit comments

Comments
 (0)