Skip to content

Latest commit

 

History

History
325 lines (141 loc) · 8.56 KB

error.md

File metadata and controls

325 lines (141 loc) · 8.56 KB

Module 0x1::error

This module defines a set of canonical error codes which are optional to use by applications for the abort and assert! features.

Canonical error codes use the 3 lowest bytes of the u64 abort code range (the upper 5 bytes are free for other use). Of those, the highest byte represents the error category and the lower two bytes the error reason. Given an error category 0x1 and a reason 0x3, a canonical abort code looks as 0x10003.

A module can use a canonical code with a constant declaration of the following form:

///  An invalid ASCII character was encountered when creating a string.
const EINVALID_CHARACTER: u64 = 0x010003;

This code is both valid in the worlds with and without canonical errors. It can be used as a plain module local error reason understand by the existing error map tooling, or as a canonical code.

The actual canonical categories have been adopted from Google's canonical error codes, which in turn are derived from Unix error codes see here. Each code has an associated HTTP error code which can be used in REST apis. The mapping from error code to http code is not 1:1; error codes here are a bit richer than HTTP codes.

Constants

Concurrency conflict, such as read-modify-write conflict (http: 409)

const ABORTED: u64 = 7;

The resource that a client tried to create already exists (http: 409)

const ALREADY_EXISTS: u64 = 8;

Request cancelled by the client (http: 499)

const CANCELLED: u64 = 10;

Internal error (http: 500)

const INTERNAL: u64 = 11;

Caller specified an invalid argument (http: 400)

const INVALID_ARGUMENT: u64 = 1;

The system is not in a state where the operation can be performed (http: 400)

const INVALID_STATE: u64 = 3;

A specified resource is not found (http: 404)

const NOT_FOUND: u64 = 6;

Feature not implemented (http: 501)

const NOT_IMPLEMENTED: u64 = 12;

An input or result of a computation is out of range (http: 400)

const OUT_OF_RANGE: u64 = 2;

client does not have sufficient permission (http: 403)

const PERMISSION_DENIED: u64 = 5;

Out of gas or other forms of quota (http: 429)

const RESOURCE_EXHAUSTED: u64 = 9;

Request not authenticated due to missing, invalid, or expired auth token (http: 401)

const UNAUTHENTICATED: u64 = 4;

The service is currently unavailable. Indicates that a retry could solve the issue (http: 503)

const UNAVAILABLE: u64 = 13;

Function canonical

Construct a canonical error code from a category and a reason.

public fun canonical(category: u64, reason: u64): u64

Function invalid_argument

Functions to construct a canonical error code of the given category.

public fun invalid_argument(r: u64): u64

Function out_of_range

public fun out_of_range(r: u64): u64

Function invalid_state

public fun invalid_state(r: u64): u64

Function unauthenticated

public fun unauthenticated(r: u64): u64

Function permission_denied

public fun permission_denied(r: u64): u64

Function not_found

public fun not_found(r: u64): u64

Function aborted

public fun aborted(r: u64): u64

Function already_exists

public fun already_exists(r: u64): u64

Function resource_exhausted

public fun resource_exhausted(r: u64): u64

Function internal

public fun internal(r: u64): u64

Function not_implemented

public fun not_implemented(r: u64): u64

Function unavailable

public fun unavailable(r: u64): u64