fix(core): unsafe type assertions in Core File System #19712 (#19739)

Co-authored-by: Dev Randalpura <devrandalpura@google.com>
This commit is contained in:
Saurav Sharma
2026-04-03 02:14:22 +05:30
committed by GitHub
parent 6fb58bd31f
commit e5adeaca80
2 changed files with 13 additions and 13 deletions
+3 -6
View File
@@ -10,6 +10,7 @@ import * as path from 'node:path';
import type { FileDiscoveryService } from '../services/fileDiscoveryService.js'; import type { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import type { FileFilteringOptions } from '../config/constants.js'; import type { FileFilteringOptions } from '../config/constants.js';
import { debugLogger } from './debugLogger.js'; import { debugLogger } from './debugLogger.js';
import { getErrorMessage } from './errors.js';
// Simple console logger for now. // Simple console logger for now.
// TODO: Integrate with a more robust server-side logger. // TODO: Integrate with a more robust server-side logger.
const logger = { const logger = {
@@ -80,10 +81,8 @@ export async function bfsFileSearch(
return { currentDir, entries }; return { currentDir, entries };
} catch (error) { } catch (error) {
// Warn user that a directory could not be read, as this affects search results. // Warn user that a directory could not be read, as this affects search results.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const message = (error as Error)?.message ?? 'Unknown error';
debugLogger.warn( debugLogger.warn(
`[WARN] Skipping unreadable directory: ${currentDir} (${message})`, `[WARN] Skipping unreadable directory: ${currentDir} (${getErrorMessage(error)})`,
); );
if (debug) { if (debug) {
logger.debug(`Full error for ${currentDir}:`, error); logger.debug(`Full error for ${currentDir}:`, error);
@@ -154,10 +153,8 @@ export function bfsFileSearchSync(
foundFiles, foundFiles,
); );
} catch (error) { } catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const message = (error as Error)?.message ?? 'Unknown error';
debugLogger.warn( debugLogger.warn(
`[WARN] Skipping unreadable directory: ${currentDir} (${message})`, `[WARN] Skipping unreadable directory: ${currentDir} (${getErrorMessage(error)})`,
); );
} }
} }
+10 -7
View File
@@ -49,12 +49,12 @@ export function generateCheckpointFileName(
toolCall: ToolCallRequestInfo, toolCall: ToolCallRequestInfo,
): string | null { ): string | null {
const toolArgs = toolCall.args; const toolArgs = toolCall.args;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion const rawFilePath = toolArgs['file_path'];
const toolFilePath = toolArgs['file_path'] as string;
if (!toolFilePath) { if (typeof rawFilePath !== 'string' || !rawFilePath) {
return null; return null;
} }
const toolFilePath = rawFilePath;
const timestamp = new Date() const timestamp = new Date()
.toISOString() .toISOString()
@@ -168,11 +168,14 @@ export function getCheckpointInfoList(
for (const [file, content] of checkpointFiles) { for (const [file, content] of checkpointFiles) {
try { try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion const parsed: unknown = JSON.parse(content);
const toolCallData = JSON.parse(content) as ToolCallData; const result = z
if (toolCallData.messageId) { .object({ messageId: z.string() })
.passthrough()
.safeParse(parsed);
if (result.success) {
checkpointInfoList.push({ checkpointInfoList.push({
messageId: toolCallData.messageId, messageId: result.data.messageId,
checkpoint: file.replace('.json', ''), checkpoint: file.replace('.json', ''),
}); });
} }