Skip to main content

Error

Enum Error 

Source
pub enum Error {
Show 48 variants InvalidPath(String), AggregatesNotAllowed, InvalidQueryParam(String), UnparsableQuery { kind: &'static str, text: String, column: usize, expected: String, }, InvalidHeader(&'static str), InvalidBody(String), UnsupportedMethod(String), InvalidRpcMethod(String), UnacceptableSchema { requested: String, exposed: Vec<String>, }, UnknownColumn { column: String, relation: String, }, InvalidRange(String), InvalidMediaType(String), MissingParameter(String), AmbiguousRequest(String), AmbiguousFunction { candidates: Vec<String>, }, AmbiguousRelationship { origin: String, target: String, candidates: Vec<(String, String)>, disambiguated: Vec<String>, }, InvalidJwt(String), NoSuitableJwtKey, JwtSecretMissing, JwtClaim(String), MissingAuth, InsufficientPermissions(String), NotFound(String), TableNotFound { name: String, suggestion: Option<String>, }, FunctionNotFound { name: String, params: Vec<String>, candidate: Option<String>, single_param: Option<String>, }, RaiseNotUnderstood(RaiseFault), MissingGeometryColumn, ColumnNotFound(String), RelationshipNotFound { origin: String, target: String, hint: Option<String>, schema: String, suggestion: Option<String>, }, NotAnEmbeddedResource(String), RelatedOrderNotPossible { origin: String, relation: String, }, NotSingular { rows: usize, }, InvalidResourcePath, InvalidPutFilters, PutLimitNotAllowed, PutMatchingPk, InvalidGucHeaders, InvalidGucStatus, MaxAffectedExceeded(i64), InvalidPreferences(Vec<String>), SchemaCacheNotLoaded, SchemaCacheLoadFailed(String), Database(DatabaseError), ConnectionPool(String), Internal(String), Config(String), InvalidPlan(String), EmbeddingError(String),
}
Expand description

Main error type for Postrust.

Variants§

§

InvalidPath(String)

§

AggregatesNotAllowed

An aggregate was requested while db-aggregates-enabled is off.

Off is the default, matching PostgREST: an unrestricted aggregate over a large table is an easy way to make a server do far more work than the request looks like it asks for.

§

InvalidQueryParam(String)

§

UnparsableQuery

A fragment of the query string the grammar could not read.

Reported the way a parser reports: what was being read, the text as the client wrote it, where reading stopped, and what would have been accepted there. All four are the client’s own input or the API’s own grammar, so none of it is a disclosure – and without them the client is told only that something in a URL it wrote is wrong.

Fields

§kind: &'static str

What was being read: filter, logic tree, order.

§text: String

The fragment, as it was written.

§column: usize

Where reading stopped, counting from one.

§expected: String

What was found there and what would have been accepted.

§

InvalidHeader(&'static str)

§

InvalidBody(String)

§

UnsupportedMethod(String)

§

InvalidRpcMethod(String)

A method a function cannot be called with.

A function is invoked with GET, HEAD or POST. The others are refused with a message that says so rather than one about the method in general, since the method is fine elsewhere in the API.

§

UnacceptableSchema

A profile header named a schema the server does not expose.

Carries the schemas that are exposed, because the client needs them to correct the request and they are part of the API’s own contract.

Fields

§requested: String
§exposed: Vec<String>
§

UnknownColumn

Fields

§column: String

The column the request named.

§relation: String

The relation it was looked for on.

§

InvalidRange(String)

§

InvalidMediaType(String)

§

MissingParameter(String)

§

AmbiguousRequest(String)

§

AmbiguousFunction

Several signatures of a function fit the arguments equally well.

Fields

§candidates: Vec<String>
§

AmbiguousRelationship

Several relationships connect the two resources and none was named.

Fields

§origin: String
§target: String
§candidates: Vec<(String, String)>

Each candidate as (cardinality, description).

§disambiguated: Vec<String>

How the client would name each candidate: big_projects!jobs.

§

InvalidJwt(String)

The token could not be decoded or its signature did not verify.

Distinct from a claims error: nothing about the token was readable, so there is nothing to say about what it claimed.

§

NoSuitableJwtKey

No key this server holds could decode the token.

Its own code would be indistinguishable from any other decode failure, so what separates it is the detail: the client is being told to look at which key signed the token, not at the token’s contents.

§

JwtSecretMissing

The server is configured to read tokens and has nothing to read them with. A fault in the deployment, not in the request.

§

JwtClaim(String)

The token decoded, but a claim was missing, malformed or unsatisfied.

§

MissingAuth

§

InsufficientPermissions(String)

§

NotFound(String)

§

TableNotFound

Fields

§name: String

The name the request asked for, schema-qualified.

§suggestion: Option<String>

A table of a very similar name, where the schema has one.

§

FunctionNotFound

No function of that name accepts the arguments supplied.

Carries what was looked for so the client can see why nothing matched: the name, the argument names it was called with, and the signature of an overload that does exist, where one does.

Fields

§name: String

The function’s qualified name, without arguments.

§params: Vec<String>

The argument names it was called with.

§candidate: Option<String>

A signature that does exist, where one does.

§single_param: Option<String>

The type of a single unnamed parameter that would also have matched, spelled as the message spells it.

Over POST the whole body can be one argument, and which type it could be is decided by the body’s media type: json/jsonb for a JSON body, text, xml or bytea for the others. Naming it says what else was looked for besides the arguments themselves.

§

RaiseNotUnderstood(RaiseFault)

A RAISE sqlstate 'PGRST' the schema wrote wrongly.

The message and the detail are both JSON documents with required keys, and a function that gets one wrong has not asked for a response – it has a bug. Reporting it as the 500 it is says so; applying half of what it asked for would not.

§

MissingGeometryColumn

Accept: application/geo+json on rows that carry no geometry.

PostGIS raises this from ST_AsGeoJSON on a record with no geometry column, and it is a database error rather than one of PostgREST’s own – so it keeps the SQLSTATE it came with.

§

ColumnNotFound(String)

§

RelationshipNotFound

Fields

§origin: String

The table the embedding started from.

§target: String

The resource the request asked to embed.

§hint: Option<String>

The !hint that was meant to identify it, if any.

§schema: String

The schema that was searched.

§suggestion: Option<String>

A relationship of a very similar name, where there is one.

§

NotAnEmbeddedResource(String)

A filter or order names something the request never embedded.

?non_existent.name=like.*x* is not a column with a dot in it, and answering it as though the prefix were meaningless would silently return the unfiltered table.

§

RelatedOrderNotPossible

Ordering by a column of a resource that yields many rows per parent.

There is no single value to order on: the parent has a list.

Fields

§origin: String

The table the request started from.

§relation: String

The embedded resource the order named.

§

NotSingular

A single object was asked for and the result is not one.

Accept: application/vnd.pgrst.object+json says the client will accept exactly one row; anything else is a negotiation failure rather than a missing resource, which is why it is 406 and not 404.

Fields

§rows: usize

How many rows the query actually returned.

§

InvalidResourcePath

A path with more segments than any resource has.

§

InvalidPutFilters

A PUT whose filters do not name exactly one row by its key.

PUT writes the row the URL names, so the URL has to name exactly one: every primary key column, with eq, and nothing else.

§

PutLimitNotAllowed

A PUT carrying a page.

§

PutMatchingPk

A PUT whose body names a different row from its URL.

§

InvalidGucHeaders

A function set response.headers to something that is not headers.

§

InvalidGucStatus

A function set response.status to something that is not a status.

§

MaxAffectedExceeded(i64)

A mutation touched more rows than Prefer: max-affected allowed.

The preference is a guard against a filter that turned out to match more than the client meant; nothing is committed when it trips.

§

InvalidPreferences(Vec<String>)

Preferences the server does not know, sent with handling=strict.

Strict handling is a request to be told rather than have them ignored.

§

SchemaCacheNotLoaded

§

SchemaCacheLoadFailed(String)

§

Database(DatabaseError)

§

ConnectionPool(String)

§

Internal(String)

§

Config(String)

§

InvalidPlan(String)

§

EmbeddingError(String)

Implementations§

Source§

impl Error

Source

pub fn status_code(&self) -> StatusCode

Get the HTTP status code for this error.

Source

pub fn code(&self) -> &'static str

Get the error code for API responses.

Source

pub fn to_json(&self) -> Value

Convert to JSON error response.

Source

pub fn details(&self) -> Option<Value>

Get additional details for the error.

Source

pub fn hint(&self) -> Option<String>

Get a hint for resolving the error.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DatabaseError> for Error

Source§

fn from(source: DatabaseError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more