Error Reference

Standard error codes returned by METAOS tools.

Error Handling Pattern

try {
  await tools.calendar.createEvent({ ... });
} catch (error) {
  // All errors include: code, message, details
  console.error(error.code);      // "CAPABILITY_DENIED"
  console.error(error.message);   // Human-readable description
  console.error(error.details);   // Additional context
  
  // Return error card to user
  return {
    type: "error",
    title: "Failed to create event",
    description: error.message
  };
}

Standard Error Codes

CodeDescriptionResolution
CAPABILITY_DENIEDUser has not granted required capabilityAdd capability to manifest, request user approval
SCOPE_VIOLATIONAttempting to access resource outside manifest scopesUpdate manifest scopes or restrict access
APPROVAL_REQUIREDAction requires user approval via approval.request()Call approval.request() before the action
APPROVAL_DENIEDUser declined approval requestInform user and cancel action
INVALID_PARAMETERTool parameter is missing or invalidCheck parameter format and required fields
INVALID_DATE_RANGEStart date is after end dateValidate date ordering before calling tool
INVALID_RECIPIENTEmail address is malformedValidate email format
FILE_NOT_FOUNDStorage path does not existCheck path exists before reading
RESOURCE_NOT_FOUNDCalendar event, message, or contact not foundVerify resource ID before accessing
STORAGE_QUOTA_EXCEEDEDUser's storage is fullInform user to free up space
NETWORK_ERRORExternal API call failedRetry with exponential backoff
RATE_LIMIT_EXCEEDEDToo many requests to tool APIImplement rate limiting, retry after delay
INTERNAL_ERRORUnexpected OS errorReport to support, retry action
TIMEOUTOperation took too longRetry with shorter timeout

Error Recovery Examples

Permission Denied

try {
  await tools.messages.send({ ... });
} catch (error) {
  if (error.code === "CAPABILITY_DENIED") {
    return {
      type: "error",
      title: "Permission Required",
      description: "Grant this agent 'messages.send' permission to send messages.",
      action: {
        label: "Grant Permission",
        url: "metaos://settings/capabilities"
      }
    };
  }
}

Retry on Network Error

async function withRetry(fn, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    try {
      return await fn();
    } catch (error) {
      if (error.code === "NETWORK_ERROR" && i < maxRetries - 1) {
        await new Promise(r => setTimeout(r, 1000 * Math.pow(2, i)));
        continue;
      }
      throw error;
    }
  }
}

// Usage
const events = await withRetry(() => 
  tools.calendar.listEvents({ start, end })
);

Graceful Degradation

try {
  const contacts = await tools.contacts.search({ name: "Alice" });
  // Use contact data
} catch (error) {
  if (error.code === "CAPABILITY_DENIED") {
    // Fallback: ask user for email manually
    return {
      type: "suggestion",
      title: "Need contact access",
      description: "Grant contacts permission or enter email manually",
      actions: [
        { label: "Grant Permission", action: "grant_capability" },
        { label: "Enter Email", action: "manual_email" }
      ]
    };
  }
}

✨ Best Practices

  • Always handle CAPABILITY_DENIED and APPROVAL_REQUIRED errors
  • Implement retry logic for NETWORK_ERROR and TIMEOUT
  • Provide helpful user messaging for permission errors
  • Log INTERNAL_ERROR to help with debugging
  • Use try/catch around all tool calls