gitbutlerapp/gitbutler · error

unterminated escape sequence in quoted message

Error message

unterminated escape sequence in quoted message

What it means

When parsing a quoted message string (e.g. from a rebase/plan editor input), a backslash escape was started but the string ended before the escaped character appeared. The parser tracks an `escaped` flag while consuming characters and bails once input is exhausted mid-escape, because the message is malformed and its intent cannot be reconstructed.

Solutions

  1. Add the character intended to follow the backslash (or remove the trailing backslash) so the quoted message ends with a proper closing quote
  2. If the backslash is literal content, escape it as `\\` so the parser consumes a complete escape sequence
  3. Regenerate the message via the library's own quote_message() instead of hand-building quoted strings

Example fix

// before
message = "fix: handle path\";
// after
message = "fix: handle path\\";
Defensive patterns

Strategy: validation

Validate before calling

fn is_balanced_quoted(s: &str) -> bool {
    let bytes = s.as_bytes();
    if bytes.len() < 2 || !bytes[0] == b'"' { return false; }
    let mut i = 1;
    while i < bytes.len() {
        match bytes[i] {
            b'\\' if i + 1 >= bytes.len() - 1 => return false, // trailing escape
            b'\\' => i += 2,
            b'"' => return i == bytes.len() - 1,
            _ => i += 1,
        }
    }
    false
}

Try / catch

match parse_message_clause(input) {
    Err(e) if e.to_string().contains("unterminated escape") => fix_trailing_backslash(input),
    Err(e) => return Err(e),
    Ok(v) => Ok(v),
}

Prevention

When it happens

Trigger: Calling parse_message_clause (via integrate-branch-upstream parsing) on an editor buffer whose quoted message ends with a trailing backslash, e.g. `"commit message\` with no character after the backslash.

Common situations: Hand-edited rebase templates or programmatically generated plan files where quoting/escaping logic dropped the final escaped character, or shell/JSON tooling stripped the character following a backslash.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/6a7167e1e2039f93. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-workspace/src/branch/integrate_branch_upstream/parsing.rs:215

            escaped = false;
            continue;
        }

        match ch {
            '\\' => escaped = true,
            '"' => {
                let trailing = input[index + ch.len_utf8()..].trim();
                if trailing.is_empty() {
                    return Ok(output);
                }
                bail!("unexpected trailing characters after quoted message");
            }
            other => output.push(other),
        }
    }

    if escaped {
        bail!("unterminated escape sequence in quoted message");
    }
    bail!("unterminated quoted message")
}

fn quote_message(message: &str) -> String {
    let mut out = String::from("\"");
    for ch in message.chars() {
        match ch {
            '\\' => out.push_str("\\\\"),
            '"' => out.push_str("\\\""),
            '\n' => out.push_str("\\n"),
            '\r' => out.push_str("\\r"),
            '\t' => out.push_str("\\t"),
            other => out.push(other),
        }
    }
    out.push('"');
    out

View on GitHub (pinned to 58e5313667)