Skip to content

Commit da599a5

Browse files
committed
fix: remove all any types from test files for TypeScript strict mode
1 parent f40e816 commit da599a5

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

src/modules/build/utils/data-processing-error-handler.spec.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('DataProcessingErrorHandler', () => {
8686
{ ...mockContext, rawData: undefined }
8787
);
8888

89-
expect(result.partialData).toBeNull();
89+
expect(result.partialData).toBeUndefined();
9090
});
9191
});
9292

@@ -256,7 +256,12 @@ describe('DataProcessingErrorHandler', () => {
256256
});
257257

258258
describe('Logging functionality', () => {
259-
let mockLogger: any;
259+
let mockLogger: {
260+
error: ReturnType<typeof vi.fn>;
261+
warn: ReturnType<typeof vi.fn>;
262+
log: ReturnType<typeof vi.fn>;
263+
debug: ReturnType<typeof vi.fn>;
264+
};
260265

261266
beforeEach(() => {
262267
mockLogger = {
@@ -265,7 +270,8 @@ describe('DataProcessingErrorHandler', () => {
265270
log: vi.fn(),
266271
debug: vi.fn(),
267272
};
268-
(DataProcessingErrorHandler as any).logger = mockLogger;
273+
// Use type assertion to set private static property
274+
(DataProcessingErrorHandler as unknown as { logger: typeof mockLogger }).logger = mockLogger;
269275
});
270276

271277
it('should log critical errors with full details', () => {
@@ -333,8 +339,8 @@ More content here.`;
333339
it('should handle empty or invalid markdown content', () => {
334340
const {extractPartialMarkdownData} = (DataProcessingErrorHandler as any);
335341

336-
expect(extractPartialMarkdownData(undefined)).toBeNull();
337-
expect(extractPartialMarkdownData('')).toBeNull();
342+
expect(extractPartialMarkdownData(undefined)).toBeUndefined();
343+
expect(extractPartialMarkdownData('')).toBeUndefined();
338344
expect(extractPartialMarkdownData('###')).toBeDefined();
339345
});
340346
});

src/modules/build/utils/file-system-error-handler.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('FileSystemErrorHandler', () => {
1111
});
1212

1313
it('should handle permission denied errors', () => {
14-
const error = new Error('Permission denied') as any;
14+
const error = new Error('Permission denied') as Error & { code: FileSystemErrorCode };
1515
error.code = FileSystemErrorCode.PERMISSION_DENIED;
1616

1717
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -29,7 +29,7 @@ describe('FileSystemErrorHandler', () => {
2929
});
3030

3131
it('should handle file not found errors', () => {
32-
const error = new Error('File not found') as any;
32+
const error = new Error('File not found') as Error & { code: FileSystemErrorCode };
3333
error.code = FileSystemErrorCode.FILE_NOT_FOUND;
3434

3535
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -47,7 +47,7 @@ describe('FileSystemErrorHandler', () => {
4747
});
4848

4949
it('should handle directory not found errors', () => {
50-
const error = new Error('Directory not found') as any;
50+
const error = new Error('Directory not found') as Error & { code: FileSystemErrorCode };
5151
error.code = FileSystemErrorCode.DIRECTORY_NOT_FOUND;
5252

5353
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -59,7 +59,7 @@ describe('FileSystemErrorHandler', () => {
5959
});
6060

6161
it('should handle no space left on device errors', () => {
62-
const error = new Error('No space left on device') as any;
62+
const error = new Error('No space left on device') as Error & { code: FileSystemErrorCode };
6363
error.code = FileSystemErrorCode.NO_SPACE_LEFT;
6464

6565
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -75,7 +75,7 @@ describe('FileSystemErrorHandler', () => {
7575
});
7676

7777
it('should handle read-only file system errors', () => {
78-
const error = new Error('Read-only file system') as any;
78+
const error = new Error('Read-only file system') as Error & { code: FileSystemErrorCode };
7979
error.code = FileSystemErrorCode.READ_ONLY_FILE_SYSTEM;
8080

8181
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -91,7 +91,7 @@ describe('FileSystemErrorHandler', () => {
9191
});
9292

9393
it('should handle too many open files errors', () => {
94-
const error = new Error('Too many open files') as any;
94+
const error = new Error('Too many open files') as Error & { code: FileSystemErrorCode };
9595
error.code = FileSystemErrorCode.TOO_MANY_OPEN_FILES;
9696

9797
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -107,7 +107,7 @@ describe('FileSystemErrorHandler', () => {
107107
});
108108

109109
it('should handle invalid path errors', () => {
110-
const error = new Error('Invalid path') as any;
110+
const error = new Error('Invalid path') as Error & { code: FileSystemErrorCode };
111111
error.code = FileSystemErrorCode.INVALID_PATH;
112112

113113
const result = FileSystemErrorHandler.handleError(error, mockOperation, mockFilePath);
@@ -154,15 +154,20 @@ describe('FileSystemErrorHandler', () => {
154154
});
155155

156156
describe('logErrorResult', () => {
157-
let mockLogger: any;
157+
let mockLogger: {
158+
error: ReturnType<typeof vi.fn>;
159+
warn: ReturnType<typeof vi.fn>;
160+
log: ReturnType<typeof vi.fn>;
161+
};
158162

159163
beforeEach(() => {
160164
mockLogger = {
161165
error: vi.fn(),
162166
warn: vi.fn(),
163167
log: vi.fn(),
164168
};
165-
(FileSystemErrorHandler as any).logger = mockLogger;
169+
// Use type assertion to set private static property
170+
(FileSystemErrorHandler as unknown as { logger: typeof mockLogger }).logger = mockLogger;
166171
});
167172

168173
it('should log critical errors with suggestions', () => {

src/modules/build/utils/file-system-error-handler.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ export class FileSystemErrorHandler {
106106
}
107107

108108
// Handle generic errors without specific error codes
109-
const genericError = error instanceof Error ? error : new Error(String(error));
110-
return this.handleGenericError(genericError, operation, filePath);
109+
return this.handleGenericError(error, operation, filePath);
111110
}
112111

113112
/**
@@ -239,11 +238,32 @@ export class FileSystemErrorHandler {
239238
/**
240239
* Handle generic/unknown file system errors
241240
*/
242-
private static handleGenericError(error: Error, operation: string, filePath: string): FileSystemErrorResult {
243-
const errorMessage = error.message || 'Unknown error';
241+
private static handleGenericError(error: unknown, operation: string, filePath: string): FileSystemErrorResult {
242+
// Extract error message from various error formats
243+
let errorMessage = 'Unknown error';
244+
let errorStack: string | undefined;
245+
246+
if (error instanceof Error) {
247+
errorMessage = error.message || 'Unknown error';
248+
errorStack = error.stack;
249+
} else if (error && typeof error === 'object') {
250+
// Handle plain objects with message property
251+
const errorObj = error as Record<string, unknown>;
252+
if (typeof errorObj.message === 'string') {
253+
errorMessage = errorObj.message;
254+
}
255+
if (typeof errorObj.stack === 'string') {
256+
errorStack = errorObj.stack;
257+
}
258+
} else if (typeof error === 'string') {
259+
errorMessage = error;
260+
} else {
261+
errorMessage = String(error);
262+
}
263+
244264
const userMessage = `File system error when ${operation}: ${filePath} - ${errorMessage}`;
245265

246-
this.logger.error(userMessage, error.stack);
266+
this.logger.error(userMessage, errorStack);
247267

248268
return {
249269
shouldContinue: false,

0 commit comments

Comments
 (0)