{"record":{"id":"ebb0969c3210a770","repo":"gitbutlerapp/gitbutler","slug":"file-suffix-is-not-allowed-must-be-one-of","errorCode":null,"errorMessage":"File suffix '{}' is not allowed. Must be one of: {}","messagePattern":"File suffix '(.+?)' is not allowed\\. Must be one of: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/tui/get_text.rs","lineNumber":66,"sourceCode":"}\n\n/// Launches the user's preferred text editor to edit some `initial_text`,\n/// identified by a `filename_safe_intent` to help the user understand what's wanted of them.\n/// Note that this string must be valid in filenames.\n///\n/// If the user has an external editor configured (via `GIT_EDITOR`, `core.editor`, or `EDITOR`),\n/// that editor is used. Otherwise, the built-in TUI editor is launched.\n///\n/// Returns the edited text (*without known encoding*) verbatim.\npub fn from_editor(\n    filename_safe_intent: &str,\n    initial_text: &str,\n    rest_text: Option<&str>,\n    file_suffix: &str,\n) -> Result<BString> {\n    const ALLOWED_SUFFIXES: &[&str] = &[\".txt\", \".md\", \".patch\"]; // feel free to add more allowed suffixes\n    if !ALLOWED_SUFFIXES.contains(&file_suffix) {\n        bail!(\n            \"File suffix '{}' is not allowed. Must be one of: {}\",\n            file_suffix,\n            ALLOWED_SUFFIXES.join(\", \")\n        );\n    }\n\n    match get_editor_command() {\n        Some(editor_cmd) => from_external_editor(\n            &editor_cmd,\n            filename_safe_intent,\n            initial_text,\n            rest_text,\n            file_suffix,\n        ),\n        None => from_builtin_editor(filename_safe_intent, initial_text, rest_text),\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/tui/get_text.rs#L48-L84","documentation":"The TUI text editor helper restricts the temporary file's suffix to a fixed allow-list (.txt, .md, .patch) so editors apply appropriate syntax modes and downstream parsing is predictable. from_editor bails if the caller passes any other file_suffix string. The allow-list is explicitly open to extension in the source.","triggerScenarios":"Calling from_editor / from_editor_no_comments / from_editor_no_comments_as_patch with a file_suffix not in [.txt, .md, .patch] — e.g. '.log', '.json', 'txt' (missing dot), or an empty string.","commonSituations":"New CLI/TUI commands passing a domain-appropriate extension that was never added to ALLOWED_SUFFIXES; typos like '.patched' or 'patch'.","solutions":["Change the caller to pass one of the allowed suffixes: .txt, .md, or .patch.","If a new extension is genuinely needed, add it to the ALLOWED_SUFFIXES constant in crates/but/src/tui/get_text.rs.","Fix typos — the suffix must include the leading dot and match exactly."],"exampleFix":"// before\nfrom_editor_no_comments(intent, None, \".commit\")?;\n// after\nfrom_editor_no_comments(intent, None, \".txt\")?;","handlingStrategy":"validation","validationCode":"const ALLOWED_SUFFIXES = ['.txt', '.md', '.patch'];\nfunction suffixAllowed(s: string): boolean {\n  return ALLOWED_SUFFIXES.includes(s);\n}","typeGuard":"function isAllowedSuffix(s: string): s is '.txt' | '.md' | '.patch' {\n  return ['.txt', '.md', '.patch'].includes(s);\n}","tryCatchPattern":null,"preventionTips":["Centralize suffix selection in one constant shared with ALLOWED_SUFFIXES","Unit-test new callers against the allow-list","Always include the leading dot in suffixes"],"tags":["validation","cli","tui","file-suffix"],"backgroundTag":"invalid-argument-value","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"}