Error codes
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.
| Code | Body | Meaning | Typical cause | What to do |
|---|---|---|---|---|
| 461 | password too short (<8) | The password is shorter than 8 | Creating a user or changing one's own password | Use a password of at least 8 characters |
| 462 | name too short (<3) | The user name is shorter than 3 | Creating a user | Use a user name of at least 3 characters |
| 463 | user exists | The user already exists | Creating a user with a taken name | Choose another name |
| 465 | db already exists | The database already exists | Adding, copying or renaming a database to a name that is taken | Choose another name or delete the existing database |
| 467 | usually db invalid: <details> | The database name or file is not valid | The name is empty, starts with ., contains /, \, : or NUL, or is audit or backups; also a database file that cannot be opened or created | Fix the name (also of the new name of a copy or rename), check the file |
| 470 | the description of the DbError | A query failed in the database | An 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 batch | Fix the query, see Embedded errors |
| 471 | storage error: <details> | The storage of the node failed | A 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 unknown | The 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 lost | The 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
| Code | Meaning | Typical cause | What to do |
|---|---|---|---|
| 400 | Bad request | An 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_level | Fix the request |
| 401 | Unauthorized | A 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 endpoints | Log in again, see troubleshooting |
| 403 | Forbidden | The 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 user | Use a user with the role needed, see Permission denied |
| 404 | Not found | A 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 well | Check the names and the owner |
| 409 | Conflict | A dashboard to add or rename to already exists (dashboard already exists: <name>) | Choose another name |
| 413 | Payload too large | The 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 |
| 415 | Unsupported media type | A JSON body sent without Content-Type: application/json, e.g. curl without -H 'Content-Type: application/json' | Set the header |
| 422 | Unprocessable entity | JSON that does not match the expected fields | Fix the body, see the OpenAPI specification |
| 500 | Internal server error | An 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 error | Check the server log |
| 503 | Service unavailable | The cluster cannot execute the request right now, see Cluster | Retry 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:
| Body | Reason |
|---|---|
cluster is not ready yet | The node has not joined the cluster yet |
this node is not the leader, the leader is node <n> / the cluster has no leader | No leader known (election in progress) or the leadership moved |
the leader has not heard from a majority of the cluster | Too many nodes are unreachable |
the cluster is busy | The log entries not yet executed exceed cluster_max_pending_bytes |
the cluster node is shutting down | The 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:
| Body | Reason |
|---|---|
the leadership was lost, the request may or may not have been executed | The leader changed while the request was running |
the cluster node is shutting down, the request may or may not have been executed | The node stopped while the request was running |
the request did not finish in time, it may or may not have been executed | The 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 replayed | The 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.
DbErrorType | Meaning |
|---|---|
DbCreate | Failed to create a new database file or structure |
InvalidIndex | An internal index was invalid or corrupted |
NotAllowed | The requested operation is not permitted |
NotEnoughData | Not enough data was available to complete deserialization |
NotFound | The requested element, alias or key was not found |
OutOfBounds | An index was outside the valid range |
Poisoned | A lock was poisoned by a panicked thread |
TypeError | A 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.
| Client | Error type | Status and description | Transport failure |
|---|---|---|---|
| Rust | agdb_api::AgdbApiError (a struct, std::error::Error) | status: u16, description: String | Status 500 when reqwest reports no status, the description is its message |
| TypeScript | AgdbApiError (a class) | status: number, description: string | Thrown by fetch_client with status 500 and the message |
| PHP | AgdbApiError (extends \Exception) | public int $status, public string $description | Thrown by CurlClient with status 500 and the cURL error |
| Python | AgdbApiError (extends Exception) | status: int, description: str | Raised 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)