Expand description
Runtime support for Conjure error types.
In a networked service, the error objects that are propagated through its codebase are responsible for two things:
- Collecting useful information that a developer can use to diagnose whatever problem caused the error.
- Controlling how the error is presented to the client.
Services implemented using Conjure’s frameworks use the Error type defined in this crate as the single error
type throughout the codebase. Errors store:
- Developer facing:
- Error::cause- the underlying cause of the error. This can be a type implementing the Rust- std::error::Errortrait, or just a- stror- Stringcontaining a description of what happened. When an- Erroris logged, the cause (and its chain of sources via- std::error::Error::source) are included as a parameter. The log-safety of that cause information is identified by the choice of constructor of the- Error.
- Error::safe_paramsand- Error::unsafe_params- key-value pairs that can be added to the error to provide context. When an- Erroris logged, these are included in the service log’s parameters. When a service- Erroris created, all of the parameters of its associated Conjure error are automatically included as params, with- ErrorType::safe_argsused to partition the parameters between safe and unsafe. Additional params can be added via- Error::with_safe_paramand- Error::with_unsafe_param.
- Error::backtraces- a sequence of backtraces to annotate the error with the state of the function call stack. A backtrace is automatically taken when the- Erroris created, and additional backtraces can be added with the- Error::with_backtracemethod. This can be used when, for example, an- Errortransfers from one thread to another. When an- Erroris logged, its backtraces will be included in the stacktrace field.
 
- Client facing:
- Error::kind- how the error should be reported to the client. There are currently three kinds:- ErrorKind::Service- a standard service error. These are constructed from a type implementing- Serializeand- ErrorType. The value is expected to serialize as a struct, with the struct’s fields being the parameters of the error. Errors defined in Conjure APIs will generate types implementing these traits. This will generate an HTTP response following the Conjure wire spec. Service errors are created with the- Error::service,- Error::service_safe,- Error::internal, and- Error::internal_safefunctions.
- ErrorKind::Throttle- an indication that the client is making too many requests and should throttle itself. This will generate a- 429 Too Many RequestsHTTP response. Throttle errors are created with the- Error::throttle,- Error::throttle_safe,- Error::throttle_for, and- Error::throttle_for_safefunctions.
- ErrorKind::Unavailable- an indication that the server is unable to handle the request. This will generate a- 503 Service UnavailableHTTP response. Unavailable errors are created with the- Error::unavailableand- Error::unavailable_safefunctions.
 
 
§Examples
Mapping a std::error::Error returned by a stdlib API into a generic internal service error:
use conjure_error::Error;
use std::fs::File;
let file = File::open("var/data/database.csv").map_err(Error::internal_safe)?;Doing the same, but including the filename as an extra parameter:
use conjure_error::Error;
use std::fs::File;
let filename = "var/data/database.csv";
let file = File::open(filename).map_err(|e| {
    Error::internal_safe(e).with_safe_param("filename", filename)
})?;Returning a specific Conjure error when there is no existing error cause:
types:
  definitions:
    errors:
      ObjectNotFound:
        namespace: MyService
        code: INVALID_ARGUMENT
        safe-args:
          objectRid: ridⓘ
use conjure_error::Error;
use my_service_api::errors::ObjectNotFound;
if !object_was_found {
    return Err(Error::service_safe("failed to find object", ObjectNotFound::new(object_rid)));
}Modules§
- conflict
- error_code 
- failed_precondition 
- internal
- invalid_argument 
- not_found 
- permission_denied 
- request_entity_ too_ large 
- serializable_error 
- timeout
Structs§
- Backtrace
- A backtrace associated with an Error.
- Conflict
- A generic CONFLICTerror.
- Error
- A standard error type for network services.
- FailedPrecondition 
- A generic FAILED_PRECONDITIONerror.
- Internal
- A generic INTERNALerror.
- InvalidArgument 
- A generic INVALID_ARGUMENTerror.
- NotFound
- A generic NOT_FOUNDerror.
- Params
- A collection of error parameters, either safe or unsafe.
- ParamsIter 
- An iterator over the parameters of an error.
- PermissionDenied 
- A generic PERMISSION_DENIEDerror.
- RequestEntity TooLarge 
- A generic REQUEST_ENTITY_TOO_LARGEerror.
- SerializableError 
- The JSON-serializable representation of an error.
- ThrottleError 
- Information about a throttle error.
- Timeout
- A generic TIMEOUTerror.
- UnavailableError 
- Information about an unavailable error.
- WithInstance Id 
- An ErrorTypewhich wraps another and overrides its instance ID.
Enums§
- ErrorCode 
- The broad category of a Conjure error.
- ErrorKind 
- Information about the specific type of an Error.
Traits§
- ErrorType 
- A trait implemented by Conjure error types.
Functions§
- encode
- Encodes a Conjure error into its serialized form.
- stringify_parameters 
- Re-serializes the parameters of a SerializableErrorin the legacy stringified format.