connect2axum_codegen/
error.rs1use std::borrow::Cow;
2
3use uni_error::{Cause, UniKind};
4
5#[derive(Clone, Copy, Debug)]
7pub enum CodegenErrKind {
8 InvalidPluginOption,
10 UnknownPluginOption,
12 OpenApiPluginFailed,
14 OpenApiInvalidDocument,
16 OpenApiMergeConflict,
18 AsyncApiInvalidDocument,
20 FileToGenerateNotFound,
22 InvalidDescriptor,
24 InvalidHttpAnnotation,
26 UnsupportedHttpRule,
28 PathFieldNotFound,
30 RequestMessageNotFound,
32 BodyFieldNotFound,
34 TypeResolutionFailed,
36 DuplicateGeneratedIdentifier,
38 DuplicateRoute,
40}
41
42impl UniKind for CodegenErrKind {
43 fn context(&self, _cause: Option<Cause<'_>>) -> Option<Cow<'static, str>> {
44 match self {
45 Self::InvalidPluginOption => Some("invalid connect2axum plugin option".into()),
46 Self::UnknownPluginOption => Some("unknown connect2axum plugin option".into()),
47 Self::OpenApiPluginFailed => Some("OpenAPI generator failed".into()),
48 Self::OpenApiInvalidDocument => Some("invalid OpenAPI document".into()),
49 Self::OpenApiMergeConflict => Some("OpenAPI documents could not be merged".into()),
50 Self::AsyncApiInvalidDocument => Some("invalid AsyncAPI document".into()),
51 Self::FileToGenerateNotFound => {
52 Some("file_to_generate was not found in the descriptor set".into())
53 }
54 Self::InvalidDescriptor => Some("invalid protobuf descriptor".into()),
55 Self::InvalidHttpAnnotation => Some("invalid google.api.http annotation".into()),
56 Self::UnsupportedHttpRule => Some("unsupported google.api.http rule".into()),
57 Self::PathFieldNotFound => Some("google.api.http path field was not found".into()),
58 Self::RequestMessageNotFound => Some("request message was not found".into()),
59 Self::BodyFieldNotFound => Some("google.api.http body field was not found".into()),
60 Self::TypeResolutionFailed => Some("protobuf type could not be resolved".into()),
61 Self::DuplicateGeneratedIdentifier => {
62 Some("duplicate generated Rust identifier".into())
63 }
64 Self::DuplicateRoute => Some("duplicate generated route".into()),
65 }
66 }
67}
68
69pub type CodegenResult<T> = uni_error::UniResult<T, CodegenErrKind>;