nikivdev/code · error

todo title cannot be empty

Error message

todo title cannot be empty

What it means

Raised by the add function (src/todo.rs:124) when the todo title argument, after trimming whitespace, is an empty string. The library refuses to create a todo item without a title since the title is the item's only meaningful content.

Source

Thrown at src/todo.rs:124

    let now = Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true);
    let ul_id = format!("_{}", Uuid::new_v4().simple());
    let li_id = Uuid::new_v4().simple().to_string();
    format!(
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<html>\n  <head>\n    <meta charset=\"utf-8\"/>\n  </head>\n  <body>\n    <ul id=\"{}\" data-created=\"{}\" data-modified=\"{}\">\n      <li id=\"{}\" data-created=\"{}\" data-modified=\"{}\">\n        <p>{}</p>\n      </li>\n    </ul>\n  </body>\n</html>\n",
        ul_id, now, now, li_id, now, now, project_name
    )
}

fn add(
    title: &str,
    note: Option<&str>,
    session: Option<&str>,
    no_session: bool,
    status: TodoStatusArg,
) -> Result<()> {
    let trimmed = title.trim();
    if trimmed.is_empty() {
        bail!("todo title cannot be empty");
    }
    let (path, mut items) = load_items()?;
    let session_ref = resolve_session_ref(session, no_session)?;
    let now = Utc::now().to_rfc3339();
    let item = TodoItem {
        id: Uuid::new_v4().simple().to_string(),
        title: trimmed.to_string(),
        status: status_to_string(status).to_string(),
        created_at: now,
        updated_at: None,
        note: note.map(|n| n.trim().to_string()).filter(|n| !n.is_empty()),
        session: session_ref,
        external_ref: None,
        priority: None,
    };
    items.push(item.clone());
    save_items(&path, &items)?;
    println!("✓ Added {} [{}]", item.id, item.title);

View on GitHub (pinned to a747e741ae)

Solutions

  1. Provide a non-empty title: `f todo add "buy groceries"`.
  2. Check that shell variables used in the title are actually set (use "${VAR:?unset}" to fail fast).
  3. Quote the title to prevent the shell from splitting/dropping it.

Example fix

// before
f todo add "$TITLE"
// after: guard against empty/unset variable in shell
f todo add "${TITLE:?TITLE must be non-empty}"
Defensive patterns

Strategy: validation

Validate before calling

const title = process.argv[3] ?? "";
if (title.trim().length === 0) {
  throw new Error("todo title must be a non-empty string");
}
// safe to call: f todo add "<title>"

Type guard

function isNonEmptyTitle(t: unknown): t is string {
  return typeof t === "string" && t.trim().length > 0;
}

Try / catch

try {
  addTodo(title);
} catch (e) {
  if (String(e).includes("todo title cannot be empty")) {
    console.error("Pass a quoted, non-empty title");
  } else throw e;
}

Prevention

When it happens

Trigger: Calling `f todo add` (via run) with an empty string, a whitespace-only string like " ", or with the title argument missing/quoted empty in a shell script.

Common situations: Shell variable interpolation producing an empty value (`f todo add "$UNSET_VAR"`); accidentally passing only flags so the positional title is empty; copy-pasting a command with the title dropped.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/65767776834c1d2a. Report an issue: GitHub.