gitbutlerapp/gitbutler · error

is required

Error message

{field} is required

What it means

required_message validates an AI request string parameter in the N-API binding: if the value is empty or whitespace-only after trimming, it bails with '{field} is required'. Used by stream_ai_response to reject empty prompts/messages before hitting the LLM API.

Solutions

  1. Provide a non-empty message string
  2. Trim and check length before calling the API
  3. Disable the submit action in the UI while the input is empty

Example fix

// before
await streamAiResponse("")
// after
const msg = input.trim();
if (!msg) return;
await streamAiResponse(msg)
Defensive patterns

Strategy: validation

Validate before calling

// TS
if (!message || !message.trim()) {
  throw new Error('message is required');
}

Type guard

const isNonEmptyMessage = (v: unknown): v is string =>
  typeof v === 'string' && v.trim().length > 0;

Try / catch

// TS
try {
  await streamAiResponse(message);
} catch (e) {
  if (String(e).includes('is required')) showToast('Enter a message first');
  else throw e;
}

Prevention

When it happens

Trigger: Calling stream_ai_response (directly or from JS/TS via N-API) with an empty or whitespace-only message/prompt string.

Common situations: UI sending an empty input box value, a variable that was never populated, or trim-related regressions stripping the whole message.

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

Appendix: source

Thrown at crates/but-napi/src/ai.rs:60

                }
            },
        )?;
        response
            .filter(|response| !response.trim().is_empty())
            .context("AI provider returned an empty response")
    })
    .await
    .context("AI response task failed")
    .and_then(|result| result)
    .map_err(to_napi_err)?;

    Ok(response)
}

fn required_message<'a>(value: &'a str, field: &str) -> Result<&'a str> {
    let value = value.trim();
    if value.is_empty() {
        bail!("{field} is required")
    }
    Ok(value)
}

View on GitHub (pinned to 58e5313667)