gitbutlerapp/gitbutler · error

Hashtag cannot be empty

Error message

Hashtag cannot be empty

What it means

get_gerrit_flags throws this when a --hashtag value passed to a Gerrit push consists only of whitespace. An empty hashtag is meaningless to Gerrit and would produce a malformed push flag, so it is rejected before any push is attempted.

Solutions

  1. Pass a non-empty hashtag value: `but push --hashtag review-blocking`
  2. Check the sourcing script for unset/empty variables feeding the flag
  3. Omit the --hashtag flag entirely if no hashtag is needed

Example fix

// before
but push --hashtag ""   // error: Hashtag cannot be empty
// after
but push --hashtag my-hashtag
Defensive patterns

Strategy: validation

Validate before calling

// validate hashtag values before invoking push
const tags = hashtags.filter(t => t && t.trim().length > 0);
if (tags.length !== hashtags.length) {
  throw new Error('Hashtag values must be non-empty');
}

Type guard

function isValidHashtag(t: string): boolean {
  return typeof t === 'string' && t.trim().length > 0;
}

Try / catch

try {
  await runBut(['push', ...flags]);
} catch (e) {
  if (/Hashtag cannot be empty/.test(e.message)) {
    console.error('Provide a non-empty --hashtag value');
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `but push --hashtag ""` or `--hashtag " "`, or passing a quoted-but-empty variable from a shell script into the hashtag flag.

Common situations: Shell variables that expand to empty strings (`--hashtag "$TAG"` with unset TAG), accidental double-space arguments, or template-generated commands with blank placeholders.

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/44b9049776cf322a. Report an issue: GitHub.

Appendix: source

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

    if !gerrit_mode {
        return Ok(vec![]);
    }

    let mut flags = Vec::new();

    // Handle Wip/Ready - Ready is default if neither is specified
    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);
    }

View on GitHub (pinned to 58e5313667)