References

Error codes

Reference of agdb_server HTTP status codes, embedded DbError types and the errors of the Rust, TypeScript, PHP and Python API clients

This page lists the errors you can meet when working with agdb: the HTTP status codes of the server, the DbError of the embedded database and the error types of the API clients. For symptoms and fixes of common problems see also the troubleshooting guide.

Server

A failed request returns a status code and the error description as the plain text body of the response. The OpenAPI specification (see API docs) lists the codes of each endpoint.

Custom codes (46x - 47x, 52x)

The server uses codes in the 4xx and 5xx ranges that are not defined by HTTP to tell apart the errors of agdb itself.

CodeBodyMeaningTypical causeWhat to do
461password too short (<8)The password is shorter than 8Creating a user or changing one's own passwordUse a password of at least 8 characters
462name too short (<3)The user name is shorter than 3Creating a userUse a user name of at least 3 characters
463user existsThe user already existsCreating a user with a taken nameChoose another name
465db already existsThe database already existsAdding, copying or renaming a database to a name that is takenChoose another name or delete the existing database
467usually db invalid: <details>The database name or file is not validThe name is empty, starts with ., contains /, \, : or NUL, or is audit or backups; also a database file that cannot be opened or createdFix the name (also of the new name of a copy or rename), check the file
470the description of the DbErrorA query failed in the databaseAn invalid query, e.g. a missing id or alias, a type mismatch or an invalid reference to a result of an earlier query (:0) in a batchFix the query, see Embedded errors
471storage error: <details>The storage of the node failedA file system or database file error, an invalid snapshot, or an action the cluster leader gave up on after a fault (see Cluster)Check the disk and the server log; in a cluster check the data afterward
520<message>The outcome of the request is unknownThe leader lost the leadership, the node stopped, a forward failed after it may have reached the leader or the request took more than 50 s (see Cluster)Check the state before repeating a request that is not safe to repeat
521<message>The request committed, its result is lostThe node stopped or resynced before it applied the request, the message has its log index (see Cluster)The request is final, the data shows its outcome once applied

The password check counts the length of the value in bytes. It runs when a user is created and when users change their own password (not on the admin password change). User names are checked only when a user is created.

Standard codes

CodeMeaningTypical causeWhat to do
400Bad requestAn invalid user name (invalid user name '<name>': ...) or dashboard name (invalid dashboard name '<name>': use 1-... characters [A-Za-z0-9_.-], not starting with '.'), malformed JSON or an undecodable binary (application/vnd.agdb.api.v1) body, an invalid log_levelFix the request
401UnauthorizedA missing, unknown or expired token (the response has no body), wrong user name or password on login (unauthorized), a token of a user that is not the server admin on /api/v1/admin/*, a wrong cluster_token on the cluster endpointsLog in again, see troubleshooting
403ForbiddenThe user lacks the required role or the operation is not allowed, e.g. a wrong current password when changing it (invalid credentials) or adding a database or dashboard to another userUse a user with the role needed, see Permission denied
404Not foundA missing user (user not found: <name>), database (db not found: <owner>/<db>), dashboard (dashboard not found: <name>), backup (backup not found), session or token. A dashboard the user has no role on is reported as not found as wellCheck the names and the owner
409ConflictA dashboard to add or rename to already exists (dashboard already exists: <name>)Choose another name
413Payload too largeThe request body is larger than request_body_limit, a dashboard config is larger than the maximum (dashboard config too large (>N bytes)) or a request is larger than a cluster append (the request is larger than a cluster append)Send less data or raise request_body_limit / cluster_max_append_size
415Unsupported media typeA JSON body sent without Content-Type: application/json, e.g. curl without -H 'Content-Type: application/json'Set the header
422Unprocessable entityJSON that does not match the expected fieldsFix the body, see the OpenAPI specification
500Internal server errorAn unexpected failure of the server that is not a storage error, e.g. a failed internal channel or a database error that is not a query errorCheck the server log
503Service unavailableThe cluster cannot execute the request right now, see ClusterRetry later

Permission denied

A 403 caused by a role carries the body permission denied: <reason>. The reasons used by the server are admin only (the database or dashboard admin role is needed, e.g. for backup, restore, rollback, clear, convert, audit trim and managing users; a non-admin token on /api/v1/admin/* gets 401), owner only, write rights required, dashboard users only, cannot change role of db owner, cannot change role of dashboard owner, cannot remove owner, cannot add dashboard to another user and mutable queries not allowed, use exec_mut endpoint (a mutable query sent to exec). The roles are described in the server reference.

Cluster

In a cluster a write goes through the leader and a node that is not the leader forwards it. A 503 was not executed and is safe to retry, its body tells the reason:

BodyReason
cluster is not ready yetThe node has not joined the cluster yet
this node is not the leader, the leader is node <n> / the cluster has no leaderNo leader known (election in progress) or the leadership moved
the leader has not heard from a majority of the clusterToo many nodes are unreachable
the cluster is busyThe log entries not yet executed exceed cluster_max_pending_bytes
the cluster node is shutting downThe node is stopping
forward to leader failed to connect: <details>The node could not connect to the leader (retried before failing)
the password hash did not complete: <details>Hashing a password on login or a password change failed
db unavailable: <owner>/<db>: <reason>The files of the database could not be opened or a file operation on them is pending; /admin/optimize retries it
another backup or a snapshot install is running on this node / the cluster node is unavailable for backup/admin/backup could not start

A 520 may or may not have been executed:

BodyReason
the leadership was lost, the request may or may not have been executedThe leader changed while the request was running
the cluster node is shutting down, the request may or may not have been executedThe node stopped while the request was running
the request did not finish in time, it may or may not have been executedThe request took more than 50 seconds
forward to leader failed: <details>The forward failed after it may have reached the leader
the action faulted and its resources could not be stamped, it may still take effect when replayedThe leader failed to mark the data of an action that faulted

A 521 (the request was committed at index <n>, its result is lost on this node) was executed: the request is final and the data shows its outcome once the node applied it.

Check the state (e.g. with a query) before repeating a 520 request that is not safe to repeat. An action the leader itself failed to run is not retried: it fails with 471 (storage error: the action faulted, its resources are accepted as they are) and the data it touched is kept as it is on the leader. See the cluster section of the server reference for details.

Embedded errors

The embedded database reports every failure as a DbError with a category (Collections, Db, Graph, Query, Serialization, Storage), a ty of DbErrorType, a description, an optional cause and the source location. The error is printed as [<category>:<ty>] <description> (at <location>) followed by the cause chain. More in the queries reference.

DbErrorTypeMeaning
DbCreateFailed to create a new database file or structure
InvalidIndexAn internal index was invalid or corrupted
NotAllowedThe requested operation is not permitted
NotEnoughDataNot enough data was available to complete deserialization
NotFoundThe requested element, alias or key was not found
OutOfBoundsAn index was outside the valid range
PoisonedA lock was poisoned by a panicked thread
TypeErrorA type conversion or mismatch error

Create your own error with one of the constructors named after the category (collections, db, graph, query, serialization, storage) and add a cause with caused_by:

use agdb::DbError;
use agdb::DbErrorType;

let error = DbError::db(DbErrorType::NotAllowed, "name must not be empty");
let wrapped = DbError::query(DbErrorType::NotFound, "user").caused_by(error);

The closure of a transaction may return any error type E that implements From<DbError>, so errors of queries convert with ? and you can add your own:

use agdb::Db;
use agdb::DbError;
use agdb::DbId;
use agdb::QueryBuilder;

enum MyError {
    Db(DbError),
    Invalid,
}

impl From<DbError> for MyError {
    fn from(error: DbError) -> Self {
        MyError::Db(error)
    }
}

fn add_node(db: &Db, valid: bool) -> Result<DbId, MyError> {
    db.transaction_mut(|t| {
        let result = t.exec_mut(QueryBuilder::insert().nodes().count(1).query())?;

        if !valid {
            return Err(MyError::Invalid); // the transaction is rolled back
        }

        Ok(result.elements[0].id)
    })
}

On the server a DbError of a query is returned as 470 and one that originates in the storage (or a poisoned lock) as 471.

Clients

All API clients report a failed request with an error carrying the HTTP status and the description (the body of the response). The error is printed as <status>: <description> (in TypeScript with e.to_string()). A request that did not get a response (e.g. the connection failed) is reported with the status 500 and the description of the transport error.

ClientError typeStatus and descriptionTransport failure
Rustagdb_api::AgdbApiError (a struct, std::error::Error)status: u16, description: StringStatus 500 when reqwest reports no status, the description is its message
TypeScriptAgdbApiError (a class)status: number, description: stringThrown by fetch_client with status 500 and the message
PHPAgdbApiError (extends \Exception)public int $status, public string $descriptionThrown by CurlClient with status 500 and the cURL error
PythonAgdbApiError (extends Exception)status: int, description: strRaised by UrllibClient with status 500 and the message

The Rust client uses the status 0 for errors that do not originate from an HTTP response: a failure to parse JSON, a DbError (converted with From<DbError>) or a response of unexpected size.

match client.user_login("alice", "password").await {
    Ok(_) => {}
    Err(e) if e.status == 401 => println!("wrong credentials: {e}"),
    Err(e) => println!("failed: {e}"),
}
try {
  await client.user_login({ username: "alice", password: "password" });
} catch (e) {
  if (e instanceof AgdbApiError && e.status === 401) {
    console.log(e.to_string());
  }
}
try {
    $client->user_login("alice", "password");
} catch (AgdbApiError $e) {
    echo $e->status . ": " . $e->description;
}
try:
    client.user_login("alice", "password")
except AgdbApiError as e:
    print(e.status, e.description)