basecamp/kamal · error · RuntimeError

Could not find field #{field} in item #{item} in Bitwarden

Error message

Could not find field #{field} in item #{item} in Bitwarden

What it means

When a secret is requested as item/field, fetch_secrets_from_fields looks up field in the item's fields array by exact name (f["name"] == field, case-sensitive). If no custom field with that exact name exists, Kamal raises RuntimeError "Could not find field ... in Bitwarden".

Source

Thrown at lib/kamal/secrets/adapters/bitwarden.rb:47

          item_json = JSON.parse(item_json)
          if fields.any?
            results.merge! fetch_secrets_from_fields(fields, item, item_json)
          elsif item_json.dig("login", "password")
            results[item] = item_json.dig("login", "password")
          elsif item_json["fields"]&.any?
            fields = item_json["fields"].pluck("name")
            results.merge! fetch_secrets_from_fields(fields, item, item_json)
          else
            raise RuntimeError, "Item #{item} is not a login type item and no fields were specified"
          end
        end
      end
    end

    def fetch_secrets_from_fields(fields, item, item_json)
      fields.to_h do |field|
        item_field = item_json["fields"].find { |f| f["name"] == field }
        raise RuntimeError, "Could not find field #{field} in item #{item} in Bitwarden" unless item_field
        value = item_field["value"]
        [ "#{item}/#{field}", value ]
      end
    end

    def items_fields(secrets)
      {}.tap do |items|
        secrets.each do |secret|
          item, field = secret.split("/")
          items[item] ||= []
          items[item] << field
        end
      end
    end

    def signedin?(account)
      run_command("status")["status"] != "unauthenticated"
    end

View on GitHub (pinned to eee0083b38)

Solutions

  1. Inspect the item's actual field names: bw get item <name> (or the web vault) and copy the exact, case-sensitive field name
  2. Correct the request to item/ExactFieldName
  3. If the field is missing, add it as a custom field on the item in Bitwarden and bw sync

Example fix

# before
kamal secrets fetch -a bitwarden --account me@example.com myitem/Username
# => RuntimeError: Could not find field Username in item myitem in Bitwarden

# fix: field is actually lowercase in the vault
kamal secrets fetch -a bitwarden --account me@example.com myitem/username
Defensive patterns

Strategy: validation

Validate before calling

item, field = "myitem", "Username"
fields = JSON.parse(`bw get item #{item.shellescape}`)["fields"].to_a.map { |f| f["name"] }
abort "field `#{field}` missing on #{item}; available: #{fields.join(", ")}" unless fields.include?(field)

Type guard

def bitwarden_field_exists?(item, field)
  JSON.parse(`bw get item #{item.shellescape}`)["fields"].to_a.any? { |f| f["name"] == field }
end

Try / catch

begin
  adapter.fetch(["#{item}/#{field}"], account: account)
rescue RuntimeError => e
  if e.message.include?("Could not find field")
    warn "available fields: #{JSON.parse(`bw get item #{item.shellescape}`)["fields"].to_a.map { |f| f["name"] }.join(", ")}"
  end
  raise
end

Prevention

When it happens

Trigger: Requesting myitem/Username when the field is named username or login; requesting a field defined on a different item; field renamed or deleted in the web vault; requesting a standard login attribute (password/username) as if it were a custom field when it is not in fields.

Common situations: Case mismatches between deploy scripts and Bitwarden field names; fields created as hidden vs text type confusion in naming; renaming fields without updating kamal config.

Related errors


AI-assisted analysis of basecamp/kamal@eee0083b38 (2026-08-21). Data as JSON: /api/errors/4bcca5f1294e5e63. Report an issue: GitHub.