Error Codes

Every error emend can return, what it means, and what to do about it.

When something goes wrong, emend gives you an EmendAiError:

interface EmendAiError {
  readonly code: EmendErrorCode
  readonly message: string
  readonly retryable: boolean
}
  • code says what went wrong. Use it in your code, for example to show a different message for each error.
  • message is a ready-made message you can show to the user.
  • retryable is true if trying again might work. You still decide whether to show a Try again button.

All error codes

CodeRetryableDefault message
invalid_protocolNoThis request uses an unsupported emend protocol version.
invalid_requestNoThe AI request is invalid.
invalid_actionNoThat AI action is not available.
invalid_instructionNoAdd a valid instruction and try again.
context_too_largeNoThe selected context is too large for this request.
selection_requiredNoSelect some text before using this action.
pending_reviewNoReview or reject the pending document change first.
request_in_progressNoAnother AI request is already in progress.
stale_revisionNoThe document changed while this request was open. Run the action again.
abortedYesThe AI request was cancelled.
transport_errorYesThe AI service could not be reached.
provider_errorYesThe configured AI provider returned an error.
unauthorizedNoThis request is not authorized.
rate_limitedYesToo many requests. Try again shortly.
markdown_unavailableNoThis editor needs compatible Tiptap Markdown support.
schema_unsupportedNoThe editor cannot safely accept this generated content.
editor_not_configuredNoThis editor does not have emend AI configured.
confirmation_requiredNoConfirm the document replacement before applying this proposal.
apply_failedNoThe proposal could not be applied safely.
internal_errorYesThe request failed unexpectedly.

Where errors appear

  • useEditorAi().error: errors while sending the request or receiving the answer.
  • useEditorAi().reviewError: errors while previewing, accepting, or rejecting a suggestion.
  • createFetchTransport: passes on errors from the server, and turns HTTP statuses like 429 into error codes.
  • createEmendAiHandler: sends errors to the browser without exposing your server's internal details.

Create and check errors

import { createEmendError, isEmendErrorCode } from "@emend/ai"

const error = createEmendError("rate_limited")

if (isEmendErrorCode(error.code) && error.retryable) {
  // Offer a deliberate retry path.
}

createEmendError(code, message?) creates an error. You can pass your own message, but retryable always comes from the code. publicError(error, fallbackCode?) turns any thrown value into a safe error you can send to the browser.

What to do for each error

ErrorWhat to do
Invalid request or setupFix the editor, action, instruction, or package setup.
context_too_largeSelect less text, or let the AI read less, and try again.
pending_review or request_in_progressAccept, reject, or stop the current request first.
stale_revisionRemove the old suggestion and run the action again.
Transport, provider, rate limit, or internalKeep the user's text and offer a Try again button.
unauthorizedAsk the user to sign in again. Do not retry automatically.

See Troubleshooting and Limitations for common causes and fixes.

On this page