{"record":{"id":"29b09ac137db6cc2","repo":"sinelaw/fresh","slug":"ack-exited-with-code-r-exit-code-r-stderr","errorCode":null,"errorMessage":"ack exited with code ${r.exit_code}: ${r.stderr}","messagePattern":"ack exited with code (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/plugins/live_grep.ts","lineNumber":597,"sourceCode":"  // skips them automatically when a faster backend is available.\n  isAvailable: async () => {\n    try {\n      const r = await editor.spawnProcess(\"ack\", [\"--version\"], editor.getCwd());\n      return r.exit_code === 0;\n    } catch {\n      return false;\n    }\n  },\n  search: async (query, { cwd, maxResults, wholeWord, regex }) => {\n    const args = [\"--nocolor\", \"--column\", \"--smart-case\"];\n    if (regex === false) args.push(\"--literal\");\n    if (wholeWord) args.push(\"--word-regexp\");\n    args.push(\"--\", query);\n    const r = await editor.spawnProcess(\"ack\", args, cwd);\n    if (r.exit_code === 0 || r.exit_code === 1) {\n      return parseGrepOutput(r.stdout, maxResults, (msg) => editor.debug(msg)) as GrepMatch[];\n    }\n    throw new Error(`ack exited with code ${r.exit_code}: ${r.stderr}`);\n  },\n});\n\n// Note: `fff` is *not* shipped as a built-in. There's no canonical\n// \"fff\" grep tool with a known argument shape — the most popular\n// binary named `fff` is the bash file-manager\n// (https://github.com/dylanaraps/fff), which is interactive and\n// doesn't accept a search pattern as an argument. Wiring a guess\n// here would silently return zero results for that flavour. Users\n// who have their own `fff` (or any other custom tool) should\n// register it from init.ts where the exact CLI is known. The\n// starter init.ts template documents the pattern.\n\nregisterProvider({\n  name: \"grep\",\n  priority: -4,\n  isAvailable: async () => {\n    try {","sourceCodeStart":579,"sourceCodeEnd":615,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/plugins/live_grep.ts#L579-L615","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the query pattern if regex mode is enabled (ack uses Perl regex — avoid PCRE-only syntax it rejects).","Run `ack <pattern>` manually in the cwd and read stderr.","Upgrade ack (`ack --version`) if it rejects the plugin's flags.","Let provider priority fall back to rg or another backend by disabling the ack provider."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"try { await editor.spawnProcess(\"ack\", [\"--version\"], cwd); } catch { /* ack missing — use rg */ }\nif (regexMode) { try { new RegExp(query); } catch { throw new Error(`invalid regex: ${query}`); } }","typeGuard":"function ackUsable(r) { return r.exit_code === 0 && /ack/i.test(r.stdout); }","tryCatchPattern":"try {\n  results = await ackProvider.search(query, opts);\n} catch (e) {\n  if (/ack exited with code/.test(String(e))) {\n    results = await rgProvider.search(query, opts);\n  } else { throw e; }\n}","preventionTips":["Confirm ack is installed and modern enough for the plugin's flags.","Remember ack uses Perl regex — avoid syntax its engine rejects.","Prefer ripgrep; ack is a low-priority (-3) backend.","Validate user regexes before regex-mode searches."],"tags":["ack","external-process","search","exit-code"],"backgroundTag":"git-command-failed","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}