Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 31 variants ReadSpec { path: String, source: Error, }, ParseSpec { path: String, source: Error, }, ReadRefFile { file: String, source: Error, }, ParseRefFile { file: String, source: Error, }, ReadConfig { path: String, source: Error, }, ParseConfig { path: String, source: Error, }, Unimplemented(String), WriteOutput { path: String, source: Error, }, ReadOutput { path: String, source: Error, }, UnsupportedSpecVersion { document: String, version: String, hint: String, }, UnsupportedSpecKey { key: String, reason: String, hint: String, }, UnresolvedRef(String), UnsupportedRef { reference: String, reason: String, }, InvalidExtensionValue { key: String, at: String, expected: String, found: String, }, UnsupportedSchema { path: String, reason: String, }, SchemaDepthExceeded { path: String, limit: usize, }, UnsupportedOperation { method: String, path: String, reason: String, }, UnsupportedContentType { method: String, path: String, location: String, declared: String, hint: String, }, UnsupportedDefault { owner: String, property: String, declared: String, hint: String, }, InvalidPathParameter { method: String, path: String, name: String, }, UndeclaredPathParameter { method: String, path: String, name: String, }, TypeNameCollision { name: String, artifact: String, hint: String, }, PreludeShadowing { name: String, used_for: String, hint: String, }, DuplicateTypeName { name: String, hint: String, }, OperationTypeCollision { name: String, first: String, second: String, hint: String, }, RecursiveAlias { cycle: Vec<String>, hint: String, }, SchemaNameCollision { ident: String, first: String, second: String, hint: String, }, OperationNameCollision { ident: String, first: String, second: String, hint: String, }, InvalidTypeNameSuffix { suffix: String, hint: String, }, InvalidGeneratedCode { source: Error, }, Validation { problems: Vec<Error>, },
}
Expand description

Errors that can occur while loading a spec or generating code.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

ReadSpec

The spec file cannot be read from disk.

Fields

§path: String

Path that cannot be read.

§source: Error

Underlying IO error.

§

ParseSpec

The spec file cannot be parsed as OpenAPI YAML/JSON.

Fields

§path: String

Path that cannot be parsed.

§source: Error

Underlying parse error.

§

ReadRefFile

A referenced external file cannot be read from disk.

Fields

§file: String

The referenced file, as written in the $ref.

§source: Error

Underlying IO error.

§

ParseRefFile

A referenced external file cannot be parsed as OpenAPI YAML/JSON.

Fields

§file: String

The referenced file, as written in the $ref.

§source: Error

Underlying parse error.

§

ReadConfig

The configuration file cannot be read from disk.

Fields

§path: String

Path that cannot be read.

§source: Error

Underlying IO error.

§

ParseConfig

The configuration file cannot be parsed as YAML.

Fields

§path: String

Path that cannot be parsed.

§source: Error

Underlying parse error.

§

Unimplemented(String)

The requested generation mode is not implemented yet.

§

WriteOutput

Writing the generated output failed.

Fields

§path: String

Path that cannot be written.

§source: Error

Underlying IO error.

§

ReadOutput

Reading the output file for a comparison failed.

An absent file is not this error. --check reports an absent file as drift, because generation creates it. This covers a file that exists and that the process cannot read, such as a directory or a file with no read permission.

Fields

§path: String

Path that cannot be read.

§source: Error

Underlying IO error.

§

UnsupportedSpecVersion

The document declares an OpenAPI version the generator does not read.

Only 3.0.x is supported. A newer document is rejected and not read as a 3.0 document, because the dialects overlap: one whose every construct happens to parse as 3.0 would generate quietly, and one newer construct in the same file would fail with a serde message that names no version.

Fields

§document: String

The document that declares it, as a path or as the $ref that reached it. Every parsed document is checked, so the message must name which one failed.

§version: String

The openapi: value the document declares.

§hint: String

What the generator reads instead.

§

UnsupportedSpecKey

The document declares a top-level key the generator cannot generate from.

webhooks: is the case. It is a 3.1 key that carries operations, and a generator that ignores it emits no handler for any of them. Silence here reads as “the spec declares no such operation”.

Fields

§key: String

The top-level key, as written in the document.

§reason: String

Why the generator cannot generate from it.

§hint: String

What to do instead.

§

UnresolvedRef(String)

A $ref pointed at something that cannot be resolved.

§

UnsupportedRef

A $ref used a form the generator does not support yet.

Fields

§reference: String

The offending reference string.

§reason: String

Why it is unsupported.

§

InvalidExtensionValue

An x- extension carried a value of a kind the generator cannot read.

The author wrote the key to change something. A silent fallback to the default would hide that nothing changed.

Fields

§key: String

The extension key, for example x-rust-name.

§at: String

The place the key sits, for example a schema or a server URL.

§expected: String

The kind of value the key needs.

§found: String

The kind of value the document gave.

§

UnsupportedSchema

A schema combined keywords in a way the generator cannot represent.

Fields

§path: String

Dotted path to the schema for diagnostics.

§reason: String

Why it is unsupported.

§

SchemaDepthExceeded

Inline schema nesting exceeded the depth the generator will lower, guarding against stack exhaustion on hostile or pathological specs.

Fields

§path: String

Schema name / lowering hint identifying the offending inline schema.

§limit: usize

The maximum supported inline nesting depth.

§

UnsupportedOperation

An operation used a feature the server generator does not support yet.

Fields

§method: String

HTTP method of the offending operation.

§path: String

Templated request path of the offending operation.

§reason: String

Why it is unsupported.

§

UnsupportedContentType

A request or response body declares content, and no content type the generator can represent.

This is not a bodyless body. A bodyless response declares no content: at all, and 204 is the common case. A body that declares application/pdf states that a payload exists, so emitting no field for it drops the payload with no message.

Both directions report through this one variant, because both make the same statement about the same input. The remedy differs by direction, so the hint carries it.

Fields

§method: String

HTTP method of the offending operation.

§path: String

Templated request path of the offending operation.

§location: String

Which body it is, as a noun phrase for the message (request body, or a response named by its status code).

§declared: String

The declared content types, in document order, comma separated.

§hint: String
§

UnsupportedDefault

The schema default does not fit the Rust type of the field. Either the two disagree, or the value has no literal form here. A dropped default leaves the document and the code in disagreement.

Fields

§owner: String

The type that owns the property.

§property: String

The property’s name as the document writes it.

§declared: String

The offending default, as JSON.

§hint: String
§

InvalidPathParameter

A parameter declared in: path has no matching {placeholder} in the operation’s path template. An OpenAPI path parameter must appear in the path, and lowering it from the template will otherwise silently drop it from the generated signature.

Fields

§method: String

HTTP method of the offending operation.

§path: String

Templated request path of the offending operation.

§name: String

The declared path-parameter name with no matching placeholder.

§

UndeclaredPathParameter

A {placeholder} in the operation’s path template has no matching parameter declared in: path. The generator cannot know the parameter’s type, so rather than silently assume String it requires the parameter to be declared (matching the OpenAPI requirement that every path template variable have a corresponding path parameter).

Fields

§method: String

HTTP method of the offending operation.

§path: String

Templated request path of the offending operation.

§name: String

The template placeholder name with no declared parameter.

§

TypeNameCollision

A generated per-operation type name collided with a component-model name emitted in the same file.

Fields

§name: String

The clashing Rust identifier.

§artifact: String

The generated artifact that clashed (for example response enum).

§hint: String

How to resolve the clash. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

PreludeShadowing

A generated type took the name of a Rust prelude type that the emitted code writes unqualified, such as Option or Vec.

The name does not duplicate an emitted item, so no other collision check sees it. It shadows the prelude inside the generated file instead, and every use of the shadowed type there stops compiling.

Fields

§name: String

The Rust type name that shadows the prelude.

§used_for: String

What generated code can name the shadowed type for, for example every optional field. The check reads names, not uses, so the file at hand does not have to hold one.

§hint: String

How to resolve the clash. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

DuplicateTypeName

Two emitted items took one Rust type name, and at least one of them came from an inline schema that lowering hoisted to the crate root.

Two component schemas that collapse onto one identifier are reported as Error::SchemaNameCollision, which names both schemas. A hoisted inline schema has no name of its own, so this variant names the identifier only.

Fields

§name: String

The Rust type name that two emitted items take.

§hint: String

How to resolve the clash. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

OperationTypeCollision

A per-operation type took the Rust type name of a second per-operation type, or of a generator interface.

Every per-operation type name derives from the method name of its operation and a fixed suffix, so two of them clash when a configured suffix makes them equal, or when two method names differ only by a suffix that another artifact also adds. The same suffix can also give a per-operation type the fixed name of a requested interface, such as the Api trait.

A clash with a model is reported as Error::TypeNameCollision instead, because the remedy names the schema and not an operation.

Fields

§name: String

The Rust type name that both items take.

§first: String

The item that claimed the name first, in document order, as a noun phrase. A per-operation type names its kind and its operation. A generator interface names what emits it and holds no operation, because the name is fixed and belongs to no operation.

§second: String

The item that collided with first, always a per-operation type, in the same form.

§hint: String

How to resolve the clash. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

RecursiveAlias

Two or more type aliases refer to each other in a cycle.

type A = B; type B = A; is a cycle rustc rejects with E0391, and no amount of indirection fixes it: a Box around either side still expands forever. The recursion pass boxes a struct field or a union variant, and a cycle made only of aliases offers neither.

Fields

§cycle: Vec<String>

The alias names on the cycle, in the order the walk met them.

§hint: String

How to break the cycle. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

SchemaNameCollision

Two component schema names collapsed onto one Rust identifier.

The generator will not choose which schema keeps the plain name, because that choice belongs to the spec author.

Fields

§ident: String

The Rust identifier that both schemas produce.

§first: String

The schema that claimed the identifier first, in document order.

§second: String

The schema that collided with first.

§hint: String

How to resolve the clash. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

OperationNameCollision

Two operations collapsed onto one Rust method name.

Every artifact of an operation derives from this one name, so the file holds a duplicate trait method, response enum, and handler, and the router points both routes at one handler. The generator will not choose which operation keeps the plain name, because that choice belongs to the spec author.

Fields

§ident: String

The Rust method name that both operations produce.

§first: String

method path of the operation that claimed the name first, in document order.

§second: String

method path of the operation that collided with first.

§hint: String

How to resolve the clash. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

InvalidTypeNameSuffix

output-options.type-name-suffix holds no identifier characters.

Casing drops punctuation and separators, so a suffix such as - or _ adds nothing to a type name. The generator cannot resolve a collision with such a suffix, because the second name stays the same as the first.

Fields

§suffix: String

The configured suffix, as written in the config.

§hint: String

How to resolve the problem. Rendered by the console as a hint, and not by Display, so the console does not print it twice.

§

InvalidGeneratedCode

The generated token stream was not valid Rust (internal bug).

Fields

§source: Error

Underlying syn parse error.

§

Validation

One pass found several independent semantic problems.

This variant holds two or more problems. One problem returns as itself, so a caller can match that variant. See crate::lower::validate::Diagnostics::into_result. This variant never nests, because the collector holds leaf errors only.

Fields

§problems: Vec<Error>

The problems, in discovery order.

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, f: &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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin 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, 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> 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 = Infallible

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.