yamadashy/repomix · error

An unexpected error occurred while filtering files.

Error message

An unexpected error occurred while filtering files.

What it means

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.

Source

Thrown at src/core/file/fileSearch.ts:352

    logger.trace(`Filtered ${confinedFilePaths.length} files`);

    return {
      filePaths: sortPaths(confinedFilePaths),
      emptyDirPaths: sortPaths(confinedEmptyDirPaths),
    };
  } catch (error: unknown) {
    // Re-throw PermissionError as is
    if (error instanceof PermissionError) {
      throw error;
    }

    if (error instanceof Error) {
      logger.error('Error filtering files:', error.message);
      throw new Error(`Failed to filter files in directory ${rootDir}. Reason: ${error.message}`);
    }

    logger.error('An unexpected error occurred:', error);
    throw new Error('An unexpected error occurred while filtering files.');
  }
};

export const parseIgnoreContent = (content: string): string[] => {
  if (!content) return [];

  return content.split('\n').reduce<string[]>((acc, line) => {
    const trimmedLine = line.trim();
    if (trimmedLine && !trimmedLine.startsWith('#')) {
      acc.push(trimmedLine);
    }
    return acc;
  }, []);
};

/**
 * Prepares ignore context including patterns and file patterns with git worktree handling.
 * This logic is shared across searchFiles, listDirectories, and listFiles.

View on GitHub (pinned to f465ad9093)

Solutions

  1. Check the logged 'An unexpected error occurred:' output for the actual thrown value.
  2. Update globby and related dependencies to current versions in case of a known bug.
  3. If you inject custom deps into searchFiles, ensure they only throw Error instances.
  4. Reproduce with a minimal directory/pattern set and report upstream with the logged value.

Example fix

// before: throwing a string from a custom helper used in the pipeline
throw 'scan failed'

// after
throw new Error('scan failed')
Defensive patterns

Strategy: try-catch

Type guard

const isErrorLike = (e: unknown): e is Error =>
  e instanceof Error || (typeof e === 'object' && e !== null && typeof (e as { message?: unknown }).message === 'string');

Try / catch

try {
  await repomix.pack(...);
} catch (e) {
  if (e instanceof Error && e.message === 'An unexpected error occurred while filtering files.') {
    // non-Error was thrown internally; re-run with verbose logging to capture the raw value
    console.error('Non-Error thrown during file filtering; enable trace logs and retry.');
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Faulty globby/filesystem shim behavior, monkey-patched or mocked libraries throwing non-Errors, or custom deps injected into searchFiles that violate the Error contract.

Related errors


AI-assisted analysis of yamadashy/repomix@f465ad9093 (2026-08-29). Data as JSON: /api/errors/3f7f4678addd1077. Report an issue: GitHub.