gitbutlerapp/gitbutler · error

Topic cannot be empty

Error message

Topic cannot be empty

What it means

The `but push` Gerrit integration rejects a topic flag that is empty or only whitespace. A Gerrit change topic must be a non-empty string, so pushing with one would produce an invalid Gerrit push spec; the library fails fast before constructing push flags.

Solutions

  1. Pass a non-empty topic: `but push --topic my-topic`.
  2. Omit `--topic` entirely and let `--topic-from-branch` derive it from the branch name.
  3. Trim/default the value in your script before invoking the CLI, e.g. `TOPIC="${MY_TOPIC:?topic required}"`.
  4. If deriving programmatically, fall back to the branch name when the topic is blank.

Example fix

// before
but push --topic "$TOPIC"
// after
but push --topic "${TOPIC:-$(git branch --show-current)}"
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$(echo "$TOPIC" | tr -d '[:space:]')" ]; then echo "--topic must be non-empty"; exit 1; fi
but push --topic "$TOPIC"

Prevention

When it happens

Trigger: Running `but push --topic ""` (or `--topic " "`) against a Gerrit remote, where args.topic is Some but trims to empty in get_gerrit_flags.

Common situations: Shell variables that expand to empty (e.g. `--topic "$MY_TOPIC"` with MY_TOPIC unset), scripting the CLI where a field is blank in CI, copy-pasting a command with a missing topic value.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at crates/but/src/command/legacy/push.rs:1075

    if args.wip {
        flags.push(but_gerrit::PushFlag::Wip);
    } else {
        // Default to Ready, or explicit Ready
        flags.push(but_gerrit::PushFlag::Ready);
    }

    // Handle hashtags - can be multiple
    for hashtag in &args.hashtag {
        if hashtag.trim().is_empty() {
            return Err(anyhow::anyhow!("Hashtag cannot be empty"));
        }
        flags.push(but_gerrit::PushFlag::Hashtag(hashtag.clone()));
    }

    // Handle topic - at most one
    if let Some(topic) = &args.topic {
        if topic.trim().is_empty() {
            return Err(anyhow::anyhow!("Topic cannot be empty"));
        }
        flags.push(but_gerrit::PushFlag::Topic(topic.clone()));
    } else if args.topic_from_branch {
        flags.push(but_gerrit::PushFlag::Topic(branch_name.to_string()));
    }

    // Handle private flag
    if args.private {
        flags.push(but_gerrit::PushFlag::Private);
    }

    Ok(flags)
}

fn resolve_branch_name(
    ctx: &mut Context,
    id_map: &IdMap,
    branch_id: &str,

View on GitHub (pinned to 58e5313667)