Crate conjure_error

Crate conjure_error 

Source
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:

§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 CONFLICT error.
Error
A standard error type for network services.
FailedPrecondition
A generic FAILED_PRECONDITION error.
Internal
A generic INTERNAL error.
InvalidArgument
A generic INVALID_ARGUMENT error.
NotFound
A generic NOT_FOUND error.
Params
A collection of error parameters, either safe or unsafe.
ParamsIter
An iterator over the parameters of an error.
PermissionDenied
A generic PERMISSION_DENIED error.
RequestEntityTooLarge
A generic REQUEST_ENTITY_TOO_LARGE error.
SerializableError
The JSON-serializable representation of an error.
ThrottleError
Information about a throttle error.
Timeout
A generic TIMEOUT error.
UnavailableError
Information about an unavailable error.
WithInstanceId
An ErrorType which 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 SerializableError in the legacy stringified format.