{"record":{"id":"e945aa82f7cb4315","repo":"gitbutlerapp/gitbutler","slug":"pr-template-exists-but-must-be-valid-utf-8-text-or","errorCode":null,"errorMessage":"PR template exists but must be valid UTF-8 text or markdown","messagePattern":"PR template exists but must be valid UTF-8 text or markdown","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-api/src/legacy/forge.rs","lineNumber":81,"sourceCode":"    let forge_repo_info = but_forge::derive_forge_repo_info(&base_remote_url)\n        .context(\"No forge could be determined for this repository branch\")?;\n    let forge_push_repo_info = if base_remote_url != push_remote_url {\n        Some(\n            but_forge::derive_forge_repo_info(&push_remote_url)\n                .context(\"Failed to derive forge information for the push repository\")?,\n        )\n    } else {\n        None\n    };\n    Ok((forge_repo_info, forge_push_repo_info))\n}\n\nfn review_template_content(file: FileInfo) -> Result<String> {\n    if file.size.is_none() {\n        return Ok(String::new());\n    }\n    if !file.is_valid_utf8() {\n        anyhow::bail!(\"PR template exists but must be valid UTF-8 text or markdown\");\n    }\n    Ok(file.content.unwrap_or_default())\n}\n\n/// (Deprecated) Get the list of PR template paths for the given project and forge.\n/// This function is deprecated in favor of `list_available_review_templates`.\n#[but_api]\n#[instrument(err(Debug))]\npub fn pr_templates(ctx: &but_ctx::Context, forge: ForgeName) -> Result<Vec<String>> {\n    Ok(available_review_templates(&ctx.workdir_or_fail()?, &forge))\n}\n\n/// Get the forge provider name.\n///\n/// This is determined by the forge the base branch is pointing to.\n/// Returns no value when the project has no target yet or its target forge is unknown.\n#[but_api(napi)]\n#[instrument(err(Debug))]","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-api/src/legacy/forge.rs#L63-L99","documentation":"review_template_content reads a forge PR/review template file and requires its content to be valid UTF-8. If the file exists, has a size, but fails the UTF-8 validity check (i.e. it is binary), this error is thrown. Templates must be text or markdown.","triggerScenarios":"Fetching a PR template from a repository or forge where the template file (e.g. PULL_REQUEST_TEMPLATE.md or a custom path) contains binary/non-UTF-8 bytes.","commonSituations":"A repo where the template file was written with a non-UTF-8 encoding (UTF-16, Latin-1 with invalid sequences) or is actually a binary file accidentally placed at the template path.","solutions":["Re-encode the template file as UTF-8 (e.g. iconv -f UTF-16 -t UTF-8)","Replace the file with a plain-text/markdown template","Verify with `file .github/PULL_REQUEST_TEMPLATE.md` that it is ASCII/UTF-8 text"],"exampleFix":"// before (UTF-16 file at template path)\n// after\n$ iconv -f UTF-16 -t UTF-8 template.md -o PULL_REQUEST_TEMPLATE.md","handlingStrategy":"validation","validationCode":"const buf = await readFile(templatePath);\nif (!isValidUtf8(buf)) throw new Error('Template must be UTF-8 text');","typeGuard":"function isUtf8Text(buf) {\n  try { new TextDecoder('utf-8', { fatal: true }).decode(buf); return true; }\n  catch { return false; }\n}","tryCatchPattern":"try {\n  const tpl = await getPrTemplate(projectId);\n} catch (e) {\n  if (String(e).includes('valid UTF-8')) {\n    tpl = ''; // fall back to default template\n  } else throw e;\n}","preventionTips":["Commit templates as UTF-8 text only","Validate template encoding in CI with `file` or an encoding linter","Avoid copying binary files into template paths"],"tags":["rust","forge","encoding"],"backgroundTag":"unexpected-response-shape","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}