Overview
The ACP Dart SDK provides comprehensive error handling through theRequestError class and automatic error mapping between Dart exceptions and JSON-RPC error codes.
RequestError
TheRequestError class represents errors that occur during ACP communication. It implements the Exception interface and maps to JSON-RPC 2.0 error codes.
The JSON-RPC 2.0 error code
A human-readable error message
Optional additional error data providing context
Standard Error Factories
The SDK provides factory methods for all standard JSON-RPC errors:Protocol Errors
Code:
Invalid JSON was received. An error occurred while parsing the JSON text.
-32700Invalid JSON was received. An error occurred while parsing the JSON text.
Code:
The JSON sent is not a valid request object.
-32600The JSON sent is not a valid request object.
Code:
The method does not exist or is not available.
-32601The method does not exist or is not available.
Code:
Invalid method parameters. Used for validation failures.
-32602Invalid method parameters. Used for validation failures.
Code:
Internal JSON-RPC error. Used for unexpected runtime failures.
-32603Internal JSON-RPC error. Used for unexpected runtime failures.
Application Errors
Code:
Authentication is required before this operation can be performed.
-32000Authentication is required before this operation can be performed.
Code:
The requested resource (such as a file) was not found.
-32002The requested resource (such as a file) was not found.
Code:
The request was cancelled by the client or due to
-32800The request was cancelled by the client or due to
$/cancel_request.Error Code Reference
| Code | Name | Description | When to Use |
|---|---|---|---|
-32700 | Parse error | Invalid JSON | Malformed JSON in message |
-32600 | Invalid Request | Invalid request object | Missing required fields |
-32601 | Method not found | Unknown method | Unsupported method name |
-32602 | Invalid params | Invalid parameters | Type/validation errors |
-32603 | Internal error | Internal error | Unexpected exceptions |
-32000 | Auth required | Authentication needed | User must authenticate |
-32002 | Resource not found | Resource missing | File/session not found |
-32800 | Cancelled | Request cancelled | Client cancellation |
Automatic Error Mapping
The SDK automatically maps Dart exceptions to appropriate JSON-RPC errors:Parameter validation failures (TypeError, FormatException, ArgumentError) automatically become
-32602 Invalid params errors.Unexpected runtime failures automatically become -32603 Internal error errors without exposing internal details.Usage Examples
Throwing Errors in Handlers
Catching Errors
Custom Error Data
Validation Errors
Error Response Structure
Errors are serialized to JSON-RPC error responses:ErrorResponse Class
Converting Errors
Best Practices
Use Specific Errors
Use the appropriate factory method for each error type rather than creating generic errors
Include Context
Provide helpful error data to aid debugging (field names, invalid values, etc.)
Never Expose Internals
Use
internalError() for unexpected exceptions to avoid exposing implementation detailsValidate Early
Validate parameters early and throw
invalidParams before processing beginsError Handling Patterns
Retry Logic
Error Logging
Related Documentation
Connection
Error handling in connections
Error Handling Guide
Comprehensive error handling patterns
Protocol Spec
JSON-RPC 2.0 specification