Egonex-AI/Understand-Anything · error

Invalid path in git diff for status ${status}

Error message

Invalid path in git diff for status ${status}

What it means

parseNameStatusZ throws when a non-rename/copy git name-status entry yields no valid path after normalization. A status code was read but the following NUL-separated field is missing or normalizes to empty, so the change record would be unusable.

Source

Thrown at understand-anything-plugin/skills/understand/prepare-incremental.mjs:174

}

function parseNameStatusZ(output) {
  if (!output) return [];
  const fields = output.split('\0');
  if (fields.at(-1) === '') fields.pop();
  const changes = [];
  for (let i = 0; i < fields.length;) {
    const status = fields[i++];
    if (!status) continue;
    const kind = status[0];
    if (kind === 'R' || kind === 'C') {
      const oldPath = normalizeRelativePath(fields[i++]);
      const newPath = normalizeRelativePath(fields[i++]);
      if (!oldPath || !newPath) throw new Error(`Invalid ${kind} path in git diff`);
      changes.push({ status, oldPath, newPath });
    } else {
      const path = normalizeRelativePath(fields[i++]);
      if (!path) throw new Error(`Invalid path in git diff for status ${status}`);
      changes.push({ status, path });
    }
  }
  return changes;
}

function pathsFromChanges(changes) {
  const paths = [];
  for (const change of changes) {
    if (change.path) paths.push(change.path);
    if (change.oldPath) paths.push(change.oldPath);
    if (change.newPath) paths.push(change.newPath);
  }
  return sorted(paths);
}

function parseNulPaths(output) {
  return output

View on GitHub (pinned to 07edf82a04)

Solutions

  1. Re-run `git diff --name-status -z <baseCommit>` and verify each status line is followed by a path
  2. Check the filename for characters that normalizeRelativePath may reject (leading slashes, '..' traversal, quoting)
  3. Retry the git command — transient truncation resolves on re-run
  4. Fall back to a full analysis run instead of the incremental path

Example fix

// before
if (!path) throw new Error(`Invalid path in git diff for status ${status}`);
// after
if (!path) {
  console.warn(`Skipping entry with invalid path for status ${status}`);
  continue;
}
Defensive patterns

Strategy: validation

Validate before calling

const raw = execSync(`git diff --name-status -z ${baseCommit}`).toString();
if (!raw.endsWith('\0') && raw.length > 0) throw new Error('Truncated git diff output');

Type guard

function hasPathField(fields, i) { return typeof fields[i] === 'string' && fields[i].length > 0; }

Try / catch

try {
  const changes = parseNameStatusZ(rawDiff);
} catch (err) {
  if (String(err.message).includes('Invalid path in git diff')) {
    return retryOrFullAnalysis();
  }
  throw err;
}

Prevention

When it happens

Trigger: A truncated or malformed `git diff --name-status -z` stream where the path field for a status like A, D, or M is absent or rejected by normalizeRelativePath.

Common situations: Interruption or truncation of git output (memory limits, subprocess buffering issues), unusual filenames the normalizer drops, or a mismatch between the git flags used to produce the diff and what the parser expects.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of Egonex-AI/Understand-Anything@07edf82a04 (2026-09-07). Data as JSON: /api/errors/00b6bbd031fe70f7. Report an issue: GitHub.