{"record":{"id":"12553f5eadc9156e","repo":"CherryHQ/cherry-studio","slug":"invalid-arguments-for-read-parsed-error","errorCode":null,"errorMessage":"Invalid arguments for read: ${parsed.error}","messagePattern":"Invalid arguments for read: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ai/mcp/servers/filesystem/tools/read.ts","lineNumber":34,"sourceCode":"  name: 'read',\n  description: `Reads a file from the local filesystem.\n\n- Only files within the configured workspace root can be read\n- The file_path parameter must resolve within the configured workspace root\n- By default, reads up to 2000 lines starting from the beginning\n- You can optionally specify a line offset and limit for long files\n- Any lines longer than 2000 characters will be truncated\n- Results are returned with line numbers starting at 1\n- Binary files are detected and rejected with an error\n- Empty files return a warning`,\n  inputSchema: z.toJSONSchema(ReadToolSchema)\n}\n\n// Handler implementation\nexport async function handleReadTool(args: unknown, baseDir: string) {\n  const parsed = ReadToolSchema.safeParse(args)\n  if (!parsed.success) {\n    throw new Error(`Invalid arguments for read: ${parsed.error}`)\n  }\n\n  const filePath = parsed.data.file_path\n  const validPath = await validatePath(filePath, baseDir)\n\n  // Check if file exists\n  try {\n    const stats = await fs.stat(validPath)\n    if (!stats.isFile()) {\n      throw new Error(`Path is not a file: ${filePath}`)\n    }\n  } catch (error: any) {\n    if (error.code === 'ENOENT') {\n      throw new Error(`File not found: ${filePath}`)\n    }\n    throw error\n  }\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/filesystem/tools/read.ts#L16-L52","documentation":"Zod safeParse on the read tool's arguments failed. ReadToolSchema requires a string `file_path` and accepts optional numeric `offset` and `limit`. parsed.error lists the failing fields. This is the first validation gate in handleReadTool; path-Containment (validatePath) and existence checks run only after this passes. Returned as an isError tool result by the server-level catch.","triggerScenarios":"The arguments object omits file_path, sends it as a non-string, or sends offset/limit as a non-number (e.g. the string '10'). Also fires if arguments is null/undefined.","commonSituations":"A model forgetting the file_path field; a client passing offset/limit as strings from a URL query param without coercion; schema drift after offset/limit were added or renamed.","solutions":["Provide file_path as a string. If using offset/limit, send them as numbers (1-based offset).","Read parsed.error to find the failing field and constraint.","Cross-check against z.toJSONSchema(ReadToolSchema) from the ListTools response."],"exampleFix":"// before\nthrow new Error(`Invalid arguments for read: ${parsed.error}`)\n\n// after — structured issues\nif (!parsed.success) {\n  const issues = parsed.error.issues.map(i => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ')\n  throw new Error(`Invalid arguments for read: ${issues}`)\n}","handlingStrategy":"validation","validationCode":"// Validate read args on the client.\nfunction isValidReadArgs(a: unknown): a is { file_path: string; offset?: number; limit?: number } {\n  if (typeof a !== 'object' || a === null) return false\n  const o = a as any\n  return typeof o.file_path === 'string'\n    && (o.offset === undefined || typeof o.offset === 'number')\n    && (o.limit === undefined || typeof o.limit === 'number')\n}","typeGuard":"function isReadArgs(a: unknown): a is { file_path: string; offset?: number; limit?: number } {\n  return typeof a === 'object' && a !== null && typeof (a as any).file_path === 'string'\n    && ((a as any).offset === undefined || typeof (a as any).offset === 'number')\n    && ((a as any).limit === undefined || typeof (a as any).limit === 'number')\n}","tryCatchPattern":null,"preventionTips":["Always send file_path as a string; send offset/limit as numbers if used.","Coerce offset/limit from strings (e.g. URL params) to numbers before sending.","Generate client types from z.toJSONSchema(ReadToolSchema).","Run safeParse on the client to catch missing or mistyped fields early."],"tags":["zod","validation","read","mcp-tool","filesystem"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}