Comma Agents
@comma-agents/coreTools

Error kinds

The closed set of ToolErrorKind values returned by built-in file tools, with recovery suggestions.

Error kinds

Every built-in tool returns a structured ToolError with a stable kind value from a closed enumeration. Agents and orchestration code can switch on kind without parsing message strings; recoverable errors include a suggestedNextAction describing what to do next.

ToolError

The full structured failure value.

Prop

Type

Usage

Switch on error.kind to handle failures programmatically without parsing message strings. Recoverable errors include suggestedNextAction describing what to do next:

const result = await tool.edit_file({
  path: "src/server.ts",
  expectedSha256: read.data.sha256,
  edits: [{ oldText: "PORT = 3000", newText: "PORT = 4000" }],
});

if (!result.ok) {
  switch (result.error.kind) {
    case "stale_file": {
      const fresh = await tool.read_file({ path: "src/server.ts" });
      // Recompute edit with fresh sha256 and retry.
      break;
    }
    case "old_text_not_found": {
      const current = await tool.read_file({ path: "src/server.ts" });
      // Locate the correct text in current.data.content and retry.
      break;
    }
    case "multiple_matches": {
      // Make oldText more specific or pass replaceAll: true.
      break;
    }
    default:
      // Non-recoverable — report and move on.
      console.error(result.error.message);
  }
}

Kind reference

error.kindTypical causeRecoverable?Suggested action
not_foundA path does not exist (or is the wrong kind — file vs. directory).SometimesCall read_file or list_directory to confirm what exists, then retry with the correct path.
already_existsA destination path is occupied (create_file, move_file without overwrite, *** Add File).YesSwitch to write_file or edit_file, or move the existing file aside first.
permission_deniedA path matches forbiddenGlobs or the guard's policy chain denied the operation.NoUse a different path, or grant access via an update_policy message to the guard's chain.
outside_workspaceA path escapes the workspace jail, or is absolute when allowAbsolutePaths is not set.NoUse a workspace-relative path.
binary_fileread_file detected binary content without allowBinary: true.YesRe-call read_file with allowBinary: true.
file_too_largeA file exceeds the sandbox-configured size limit.NoRead or write the file in slices, or raise the configured cap.
stale_fileexpectedSha256 does not match the on-disk content.YesRe-read the file to obtain the current sha256 and re-apply your edit.
old_text_not_foundAn edit_file edit's oldText was not present in the file.YesRe-read the file and pick text that exists.
multiple_matchesAn edit_file edit's oldText matched more than once and replaceAll was not set.YesMake oldText more specific, or pass replaceAll: true.
overlapping_editsTwo edit_file edits would replace intersecting byte ranges.YesCombine the edits or apply them in separate calls.
patch_parse_errorAn apply_patch envelope is malformed.YesFix the envelope grammar (see Patch envelope).
patch_apply_errorA hunk did not match, or an add/delete/move pre-check failed.YesRe-read the affected files and regenerate the patch against the current content.
command_failedrun_command could not spawn or was aborted; move_file got identical from/to or a directory destination; delete_file got a directory without recursive.SometimesRead the message for the specific failure mode.
timeoutrun_command exceeded its timeoutMs.YesIncrease the timeout, narrow the command, or split it into smaller steps.
skill_unavailableload_skill was called but no skill registry is wired into the agent.NoStop attempting to load skills for the rest of the turn.
unknownAn unexpected internal failure.NoFile an issue with the captured details.

Result invariant

For every ToolResult:

  • When ok is false, error is set.
  • When ok is true, error is undefined.

data may be present in either case — for example, run_command returns the partial stdout/stderr captured up to a timeout alongside error.kind: "timeout".

On this page