Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
use frecency::domain::models::FrecencyQueryErr;
use thiserror::Error;
use uuid::Uuid;
/// Errors that can occur in the email domain.
#[derive(Debug, Error)]
pub enum EmailErr {
/// A send attempt was reused with a different approved snapshot.
#[error("Send attempt payload does not match the original request")]
SendAttemptConflict,
/// A send snapshot is invalid or its attachments have changed.
#[error("Invalid send snapshot: {0}")]
InvalidSendSnapshot(String),
/// A repository/infrastructure error.
#[error(transparent)]
RepoErr(#[from] anyhow::Error),
/// An external provider API error (e.g. Gmail API).
#[error("Provider error: {0}")]
ProviderErr(anyhow::Error),
/// Sender lookup is unavailable on this host or at the provider.
#[error("Email sender addresses are unavailable")]
SendAsUnavailable,
/// The provider grant cannot read sender settings.
#[error("Reconnect this inbox to access its sender addresses")]
SendAsPermissionRequired,
/// The requested address is not an approved sender for this inbox.
#[error("This address is not a verified sender for the selected inbox")]
InvalidSender,
/// A frecency query error.
#[error(transparent)]
Frecency(#[from] FrecencyQueryErr),
/// The referenced message was not found.
#[error("Message with id {0} not found")]
MessageNotFound(Uuid),
/// No sending inbox could be resolved: the requested link is not
/// accessible to the caller, or the caller has no primary inbox.
#[error("Email inbox not found")]
InboxNotFound,
/// The caller asked to send from an address that is none of the inboxes
/// they have connected or been delegated. The accessible addresses are
/// carried along so the caller can be told what it could have been.
#[error(
"No connected inbox matches \"{requested}\". Connected inboxes: {}.",
available.join(", ")
)]
UnknownSendingInbox {
/// The address the caller asked to send from.
requested: String,
/// The addresses of every inbox the caller can send from.
available: Vec<String>,
},
/// The referenced message has already been sent and cannot be modified.
#[error("Message with id {0} has already been sent")]
MessageAlreadySent(Uuid),
/// An older browser edit must not replace a newer send/cancel generation.
#[error("Draft changed on another device; reload before applying this edit: {0}")]
DraftGenerationConflict(Uuid),
/// Delivery has been committed, claimed, or completed and cannot be edited.
#[error("Message with id {0} is scheduled, processing, or already sent")]
MessageDeliveryConflict(Uuid),
/// The requested draft mutation cannot preserve its content.
#[error("{0}")]
InvalidDraft(String),
/// Explicit scheduled delivery requires a time in the future.
#[error("Scheduled send time must be in the future")]
InvalidScheduleTime,
/// Cannot reply to a draft message.
#[error("Cannot reply to a draft")]
CannotReplyToDraft,
/// Failed to decode base64 body content.
#[error("Failed to decode base64 HTML body")]
Base64DecodeError(#[from] base64::DecodeError),
/// Decoded bytes are not valid UTF-8.
#[error("Failed to convert decoded HTML body to UTF-8")]
Utf8Error(#[from] std::string::FromUtf8Error),
/// The referenced label was not found.
#[error("Label not found")]
LabelNotFound,
/// The label has an empty provider label ID.
#[error("Label has empty provider label ID")]
EmptyProviderLabelId,
/// No messages found for thread.
#[error("No messages found for thread")]
ThreadEmpty,
#[error("thread has no received messages and cannot be unarchived")]
ThreadHasNoInboundMessages,
/// Thread not found.
#[error("Thread not found")]
ThreadNotFound,
/// A bulk request named more threads than one request may change.
#[error("At most {0} threads can change in one request")]
TooManyThreads(usize),
/// The caller does not have permission to perform this action.
#[error("You do not have permission to perform this action")]
Unauthorized,
/// Failed to enqueue a message to a worker queue.
#[error("Enqueue error: {0}")]
EnqueueErr(anyhow::Error),
/// Invalid email filter input.
#[error("{0}")]
InvalidEmailFilter(String),
/// This host has no attachment source or storage wired, so a send that
/// names attachments cannot be honoured.
#[error("Email attachments are not available here")]
AttachmentsUnavailable,
/// A referenced document cannot be attached: it is not a file (a Macro
/// document with no stored bytes), is gone, or could not be read.
#[error("Cannot attach \"{name}\": {reason}")]
AttachmentUnavailable {
/// What the document is called, for the message the user reads.
name: String,
/// Why it cannot be attached.
reason: String,
},
/// The attachments together exceed what one email can carry.
#[error(
"Attachments total {total_bytes} bytes, over the {limit_bytes} byte limit for one email"
)]
AttachmentsTooLarge {
/// The combined raw size of every attachment requested.
total_bytes: usize,
/// The ceiling it crossed.
limit_bytes: usize,
},
/// The caller's team has `team_crm_settings.crm_enabled = false` (or no
/// row at all), so no CRM-scoped query is allowed.
#[error("CRM is disabled for this team")]
CrmDisabledForTeam,
/// A CRM-scoped query referenced a domain that does not have a matching
/// `crm_domains` row for the caller's team.
#[error("CRM domain {0} not found for this team")]
CrmDomainNotFound(String),
/// A CRM-scoped query referenced a domain whose company is hidden or
/// has `email_sync = false`.
#[error("CRM domain {0} is not permitted for CRM-scoped queries")]
CrmDomainNotPermitted(String),
/// A CRM-scoped query referenced an address with no matching
/// `crm_contacts` row for the caller's team.
#[error("CRM address {0} not found for this CRM scope")]
CrmAddressNotFound(String),
/// A CRM-scoped query referenced an address whose contact or company
/// is hidden, or whose company has `email_sync = false`.
#[error("CRM address {0} is not permitted for CRM-scoped queries")]
CrmAddressNotPermitted(String),
}