sinelaw/fresh · error

ack exited with code

Error message

ack exited with code ${r.exit_code}: ${r.stderr}

What it means

The live_grep plugin's `ack` provider throws this when the spawned ack process exits with a code other than 0 (matches found) or 1 (no matches — returned as an empty result). Other codes mean ack failed outright, usually exit 2 from a bad regex or unsupported arguments. ack's stderr is embedded in the message.

Solutions

  1. Fix the query pattern if regex mode is enabled (ack uses Perl regex — avoid PCRE-only syntax it rejects).
  2. Run `ack <pattern>` manually in the cwd and read stderr.
  3. Upgrade ack (`ack --version`) if it rejects the plugin's flags.
  4. Let provider priority fall back to rg or another backend by disabling the ack provider.
Defensive patterns

Strategy: fallback

Validate before calling

try { await editor.spawnProcess("ack", ["--version"], cwd); } catch { /* ack missing — use rg */ }
if (regexMode) { try { new RegExp(query); } catch { throw new Error(`invalid regex: ${query}`); } }

Type guard

function ackUsable(r) { return r.exit_code === 0 && /ack/i.test(r.stdout); }

Try / catch

try {
  results = await ackProvider.search(query, opts);
} catch (e) {
  if (/ack exited with code/.test(String(e))) {
    results = await rgProvider.search(query, opts);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Invoking the live-grep ack provider when: (1) the query is an invalid Perl regex in regex mode (ack exits 2), (2) the installed ack version rejects one of the constructed flags (e.g. --word-regexp, --literal, ignore-dir flags), or (3) the cwd is unreadable.

Common situations: Very old or unusual ack versions with different flag handling; malformed regex queries like '(?P<' groups not supported by ack's regex engine; ack installed via a shim that fails; searching a removed directory.

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 sinelaw/fresh@67894ca546 (2026-09-13). Data as JSON: /api/errors/29b09ac137db6cc2. Report an issue: GitHub.

Appendix: source

Thrown at crates/fresh-editor/plugins/live_grep.ts:597

  // skips them automatically when a faster backend is available.
  isAvailable: async () => {
    try {
      const r = await editor.spawnProcess("ack", ["--version"], editor.getCwd());
      return r.exit_code === 0;
    } catch {
      return false;
    }
  },
  search: async (query, { cwd, maxResults, wholeWord, regex }) => {
    const args = ["--nocolor", "--column", "--smart-case"];
    if (regex === false) args.push("--literal");
    if (wholeWord) args.push("--word-regexp");
    args.push("--", query);
    const r = await editor.spawnProcess("ack", args, cwd);
    if (r.exit_code === 0 || r.exit_code === 1) {
      return parseGrepOutput(r.stdout, maxResults, (msg) => editor.debug(msg)) as GrepMatch[];
    }
    throw new Error(`ack exited with code ${r.exit_code}: ${r.stderr}`);
  },
});

// Note: `fff` is *not* shipped as a built-in. There's no canonical
// "fff" grep tool with a known argument shape — the most popular
// binary named `fff` is the bash file-manager
// (https://github.com/dylanaraps/fff), which is interactive and
// doesn't accept a search pattern as an argument. Wiring a guess
// here would silently return zero results for that flavour. Users
// who have their own `fff` (or any other custom tool) should
// register it from init.ts where the exact CLI is known. The
// starter init.ts template documents the pattern.

registerProvider({
  name: "grep",
  priority: -4,
  isAvailable: async () => {
    try {

View on GitHub (pinned to 67894ca546)