{"record":{"id":"3f7f4678addd1077","repo":"yamadashy/repomix","slug":"an-unexpected-error-occurred-while-filtering-files","errorCode":null,"errorMessage":"An unexpected error occurred while filtering files.","messagePattern":"An unexpected error occurred while filtering files\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/core/file/fileSearch.ts","lineNumber":352,"sourceCode":"    logger.trace(`Filtered ${confinedFilePaths.length} files`);\n\n    return {\n      filePaths: sortPaths(confinedFilePaths),\n      emptyDirPaths: sortPaths(confinedEmptyDirPaths),\n    };\n  } catch (error: unknown) {\n    // Re-throw PermissionError as is\n    if (error instanceof PermissionError) {\n      throw error;\n    }\n\n    if (error instanceof Error) {\n      logger.error('Error filtering files:', error.message);\n      throw new Error(`Failed to filter files in directory ${rootDir}. Reason: ${error.message}`);\n    }\n\n    logger.error('An unexpected error occurred:', error);\n    throw new Error('An unexpected error occurred while filtering files.');\n  }\n};\n\nexport const parseIgnoreContent = (content: string): string[] => {\n  if (!content) return [];\n\n  return content.split('\\n').reduce<string[]>((acc, line) => {\n    const trimmedLine = line.trim();\n    if (trimmedLine && !trimmedLine.startsWith('#')) {\n      acc.push(trimmedLine);\n    }\n    return acc;\n  }, []);\n};\n\n/**\n * Prepares ignore context including patterns and file patterns with git worktree handling.\n * This logic is shared across searchFiles, listDirectories, and listFiles.","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/file/fileSearch.ts#L334-L370","documentation":"Fallback error from searchFiles for thrown values that are not Error instances. When the caught value lacks a message, repomix logs the raw value and throws this fixed message instead of a Reason-suffixed one.","triggerScenarios":"Something inside searchFiles' try block throws a non-Error value (string, object, undefined) instead of an Error instance — typically a bug in a dependency or a misused API, not user input.","commonSituations":"Faulty globby/filesystem shim behavior, monkey-patched or mocked libraries throwing non-Errors, or custom deps injected into searchFiles that violate the Error contract.","solutions":["Check the logged 'An unexpected error occurred:' output for the actual thrown value.","Update globby and related dependencies to current versions in case of a known bug.","If you inject custom deps into searchFiles, ensure they only throw Error instances.","Reproduce with a minimal directory/pattern set and report upstream with the logged value."],"exampleFix":"// before: throwing a string from a custom helper used in the pipeline\nthrow 'scan failed'\n\n// after\nthrow new Error('scan failed')","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const isErrorLike = (e: unknown): e is Error =>\n  e instanceof Error || (typeof e === 'object' && e !== null && typeof (e as { message?: unknown }).message === 'string');","tryCatchPattern":"try {\n  await repomix.pack(...);\n} catch (e) {\n  if (e instanceof Error && e.message === 'An unexpected error occurred while filtering files.') {\n    // non-Error was thrown internally; re-run with verbose logging to capture the raw value\n    console.error('Non-Error thrown during file filtering; enable trace logs and retry.');\n  } else throw e;\n}","preventionTips":["Keep globby and dependencies at supported versions.","If you inject custom deps, ensure they only throw Error instances.","Enable trace logging to capture the raw thrown value when it happens.","Reduce the input to a minimal repro before filing a bug."],"tags":["filesystem","globby","unexpected-error"],"backgroundTag":"unexpected-throw-non-error","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}