Skip to main content

rocketmq_error/
catalog.rs

1// Copyright 2023 The RocketMQ Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use crate::descriptor::ErrorClass;
16use crate::descriptor::ErrorCode;
17use crate::descriptor::ErrorDescriptor;
18use crate::field::fields;
19use crate::field::FieldSchema;
20use crate::projection::ProjectionSpec;
21use crate::BacktracePolicy;
22use crate::CanonicalCondition;
23use crate::CliExitCode;
24use crate::CliSpec;
25use crate::ComponentId;
26use crate::ErrorSeverity;
27use crate::Exposure;
28use crate::FaultAttribution;
29use crate::GrpcPayloadCode;
30use crate::GrpcSpec;
31use crate::GrpcStatusCode;
32use crate::HttpSpec;
33use crate::HttpStatusCode;
34use crate::RecoveryHint;
35use crate::RemotingResponseCode;
36use crate::RemotingSpec;
37
38macro_rules! define_error_catalog {
39    (
40        $(
41            $(#[$metadata:meta])*
42            $name:ident {
43                code: $code:literal,
44                class: $class:path,
45                condition: $condition:path,
46                fault: $fault:path,
47                component: $component:path,
48                public_message: $public_message:literal,
49                severity: $severity:path,
50                recovery_hint: $recovery_hint:path,
51                backtrace: $backtrace:path,
52                exposure: $exposure:path,
53                fields: [$($field:path),* $(,)?],
54                projection: {
55                    remoting: $remoting:path,
56                    grpc: {
57                        payload: $grpc_payload:path,
58                        status: $grpc_status:path,
59                    },
60                    http: $http:path,
61                    cli: $cli:path,
62                },
63            }
64        )+
65    ) => {
66        $(
67            $(#[$metadata])*
68            pub const $name: ErrorDescriptor = {
69                const CODE: ErrorCode = match ErrorCode::try_new($code) {
70                    Some(code) => code,
71                    None => panic!("invalid canonical error code"),
72                };
73                const FIELDS: &[FieldSchema] = &[$($field.schema()),*];
74
75                match ErrorDescriptor::try_new(
76                    CODE,
77                    $class,
78                    $condition,
79                    $fault,
80                    $component,
81                    $public_message,
82                    $severity,
83                    $recovery_hint,
84                    $backtrace,
85                    $exposure,
86                    ProjectionSpec::new(
87                        RemotingSpec::new($remoting),
88                        GrpcSpec::new($grpc_payload, $grpc_status),
89                        HttpSpec::new($http),
90                        CliSpec::new($cli),
91                    ),
92                    FIELDS,
93                ) {
94                    Some(descriptor) => descriptor,
95                    None => panic!("invalid descriptor field list"),
96                }
97            };
98        )+
99
100    };
101}
102
103mod auth;
104mod broker;
105mod client;
106mod controller;
107mod core;
108mod observability;
109mod protocol;
110mod proxy;
111mod route;
112mod rpc;
113mod tools;
114mod transport;
115
116pub use auth::*;
117pub use broker::*;
118pub use client::*;
119pub use controller::*;
120pub use core::*;
121pub use observability::*;
122pub use protocol::*;
123pub use proxy::*;
124pub use route::*;
125pub use rpc::*;
126pub use tools::*;
127pub use transport::*;
128
129define_error_catalog! {
130    /// Invalid request-header syntax or values.
131    PROTOCOL_HEADER_INVALID {
132        code: "protocol.header.invalid",
133        class: ErrorClass::VALIDATION,
134        condition: CanonicalCondition::InvalidArgument,
135        fault: FaultAttribution::Caller,
136        component: ComponentId::PROTOCOL,
137        public_message: "Request header is invalid",
138        severity: ErrorSeverity::Info,
139        recovery_hint: RecoveryHint::Never,
140        backtrace: BacktracePolicy::Never,
141        exposure: Exposure::Public,
142        fields: [
143            fields::OPERATION_DIAGNOSTIC,
144            fields::INVALID_VALUE_PRESENT,
145            fields::SOURCE_PRESENT,
146        ],
147        projection: {
148            remoting: RemotingResponseCode::InvalidParameter,
149            grpc: {
150                payload: GrpcPayloadCode::BadRequest,
151                status: GrpcStatusCode::InvalidArgument,
152            },
153            http: HttpStatusCode::BAD_REQUEST,
154            cli: CliExitCode::USAGE,
155        },
156    }
157    /// Missing routing information for a topic.
158    ROUTE_TOPIC_NOT_FOUND {
159        code: "route.topic.not_found",
160        class: ErrorClass::ROUTING,
161        condition: CanonicalCondition::NotFound,
162        fault: FaultAttribution::RemotePeer,
163        component: ComponentId::ROUTE,
164        public_message: "Topic route was not found",
165        severity: ErrorSeverity::Warn,
166        recovery_hint: RecoveryHint::RefreshRoute,
167        backtrace: BacktracePolicy::Never,
168        exposure: Exposure::Public,
169        fields: [fields::TOPIC],
170        projection: {
171            remoting: RemotingResponseCode::TopicNotExist,
172            grpc: {
173                payload: GrpcPayloadCode::TopicNotFound,
174                status: GrpcStatusCode::NotFound,
175            },
176            http: HttpStatusCode::NOT_FOUND,
177            cli: CliExitCode::NOT_FOUND,
178        },
179    }
180    /// Invalid authentication credentials or signature.
181    AUTH_CREDENTIALS_INVALID {
182        code: "auth.credentials.invalid",
183        class: ErrorClass::AUTHENTICATION,
184        condition: CanonicalCondition::Unauthenticated,
185        fault: FaultAttribution::Caller,
186        component: ComponentId::AUTH,
187        public_message: "Authentication credentials are invalid",
188        severity: ErrorSeverity::Error,
189        recovery_hint: RecoveryHint::RefreshCredentials,
190        backtrace: BacktracePolicy::Never,
191        exposure: Exposure::Generic,
192        fields: [fields::CREDENTIALS_PRESENT],
193        projection: {
194            remoting: RemotingResponseCode::NoPermission,
195            grpc: {
196                payload: GrpcPayloadCode::Unauthorized,
197                status: GrpcStatusCode::Unauthenticated,
198            },
199            http: HttpStatusCode::UNAUTHORIZED,
200            cli: CliExitCode::PERMISSION,
201        },
202    }
203    /// Requested authentication user does not exist.
204    AUTH_USER_NOT_FOUND {
205        code: "auth.user.not_found",
206        class: ErrorClass::AUTHENTICATION,
207        condition: CanonicalCondition::NotFound,
208        fault: FaultAttribution::Caller,
209        component: ComponentId::AUTH,
210        public_message: "User does not exist",
211        severity: ErrorSeverity::Warn,
212        recovery_hint: RecoveryHint::Never,
213        backtrace: BacktracePolicy::Never,
214        exposure: Exposure::Generic,
215        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
216        projection: {
217            remoting: RemotingResponseCode::UserNotExist,
218            grpc: {
219                payload: GrpcPayloadCode::NotFound,
220                status: GrpcStatusCode::NotFound,
221            },
222            http: HttpStatusCode::NOT_FOUND,
223            cli: CliExitCode::NOT_FOUND,
224        },
225    }
226    /// Permission denied for an authenticated principal.
227    AUTH_PERMISSION_DENIED {
228        code: "auth.permission.denied",
229        class: ErrorClass::AUTHORIZATION,
230        condition: CanonicalCondition::PermissionDenied,
231        fault: FaultAttribution::Caller,
232        component: ComponentId::AUTH,
233        public_message: "Permission was denied",
234        severity: ErrorSeverity::Error,
235        recovery_hint: RecoveryHint::Never,
236        backtrace: BacktracePolicy::Never,
237        exposure: Exposure::Public,
238        fields: [fields::OPERATION],
239        projection: {
240            remoting: RemotingResponseCode::NoPermission,
241            grpc: {
242                payload: GrpcPayloadCode::Forbidden,
243                status: GrpcStatusCode::PermissionDenied,
244            },
245            http: HttpStatusCode::FORBIDDEN,
246            cli: CliExitCode::PERMISSION,
247        },
248    }
249    /// Saturated transport admission queue.
250    TRANSPORT_ADMISSION_QUEUE_SATURATED {
251        code: "transport.admission.queue_saturated",
252        class: ErrorClass::CAPACITY,
253        condition: CanonicalCondition::ResourceExhausted,
254        fault: FaultAttribution::LocalResource,
255        component: ComponentId::TRANSPORT,
256        public_message: "Transport admission queue is saturated",
257        severity: ErrorSeverity::Warn,
258        recovery_hint: RecoveryHint::Backoff,
259        backtrace: BacktracePolicy::Never,
260        exposure: Exposure::Public,
261        fields: [fields::REMOTE_ADDR],
262        projection: {
263            remoting: RemotingResponseCode::SystemBusy,
264            grpc: {
265                payload: GrpcPayloadCode::TooManyRequests,
266                status: GrpcStatusCode::ResourceExhausted,
267            },
268            http: HttpStatusCode::TOO_MANY_REQUESTS,
269            cli: CliExitCode::TEMPORARY_FAILURE,
270        },
271    }
272    /// Operation sent to a controller that is not the leader.
273    CONTROLLER_LEADERSHIP_NOT_LEADER {
274        code: "controller.leadership.not_leader",
275        class: ErrorClass::ROUTING,
276        condition: CanonicalCondition::FailedPrecondition,
277        fault: FaultAttribution::LocalResource,
278        component: ComponentId::CONTROLLER,
279        public_message: "Controller is not the leader",
280        severity: ErrorSeverity::Warn,
281        recovery_hint: RecoveryHint::RefreshLeader,
282        backtrace: BacktracePolicy::Never,
283        exposure: Exposure::Public,
284        fields: [fields::LEADER_ID],
285        projection: {
286            remoting: RemotingResponseCode::ControllerNotLeader,
287            grpc: {
288                payload: GrpcPayloadCode::InternalError,
289                status: GrpcStatusCode::FailedPrecondition,
290            },
291            http: HttpStatusCode::CONFLICT,
292            cli: CliExitCode::DATA,
293        },
294    }
295    /// Timed-out transport connection attempt.
296    TRANSPORT_CONNECTION_TIMEOUT {
297        code: "transport.connection.timeout",
298        class: ErrorClass::TIMEOUT,
299        condition: CanonicalCondition::DeadlineExceeded,
300        fault: FaultAttribution::Dependency,
301        component: ComponentId::TRANSPORT,
302        public_message: "Transport connection timed out",
303        severity: ErrorSeverity::Warn,
304        recovery_hint: RecoveryHint::Backoff,
305        backtrace: BacktracePolicy::Never,
306        exposure: Exposure::Public,
307        fields: [fields::TIMEOUT_MS, fields::REMOTE_ADDR, fields::SOURCE_PRESENT],
308        projection: {
309            remoting: RemotingResponseCode::SystemBusy,
310            grpc: {
311                payload: GrpcPayloadCode::RequestTimeout,
312                status: GrpcStatusCode::DeadlineExceeded,
313            },
314            http: HttpStatusCode::GATEWAY_TIMEOUT,
315            cli: CliExitCode::TEMPORARY_FAILURE,
316        },
317    }
318    /// Transport server startup failed.
319    TRANSPORT_START_FAILED {
320        code: "transport.start.failed",
321        class: ErrorClass::UNAVAILABLE,
322        condition: CanonicalCondition::Unavailable,
323        fault: FaultAttribution::Unknown,
324        component: ComponentId::TRANSPORT,
325        public_message: "Transport server could not be started",
326        severity: ErrorSeverity::Error,
327        recovery_hint: RecoveryHint::OperatorAction,
328        backtrace: BacktracePolicy::Never,
329        exposure: Exposure::Generic,
330        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
331        projection: {
332            remoting: RemotingResponseCode::SystemError,
333            grpc: {
334                payload: GrpcPayloadCode::InternalError,
335                status: GrpcStatusCode::Unavailable,
336            },
337            http: HttpStatusCode::SERVICE_UNAVAILABLE,
338            cli: CliExitCode::UNAVAILABLE,
339        },
340    }
341    /// Transport request dispatch failed.
342    TRANSPORT_DISPATCH_FAILED {
343        code: "transport.dispatch.failed",
344        class: ErrorClass::INTERNAL,
345        condition: CanonicalCondition::Internal,
346        fault: FaultAttribution::LocalResource,
347        component: ComponentId::TRANSPORT,
348        public_message: "Transport request dispatch failed",
349        severity: ErrorSeverity::Error,
350        recovery_hint: RecoveryHint::OperatorAction,
351        backtrace: BacktracePolicy::OnDemand,
352        exposure: Exposure::Generic,
353        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
354        projection: {
355            remoting: RemotingResponseCode::SystemError,
356            grpc: {
357                payload: GrpcPayloadCode::InternalError,
358                status: GrpcStatusCode::Internal,
359            },
360            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
361            cli: CliExitCode::SOFTWARE,
362        },
363    }
364    /// Transport response delivery failed.
365    TRANSPORT_RESPONSE_FAILED {
366        code: "transport.response.failed",
367        class: ErrorClass::INTERNAL,
368        condition: CanonicalCondition::Internal,
369        fault: FaultAttribution::Dependency,
370        component: ComponentId::TRANSPORT,
371        public_message: "Transport response delivery failed",
372        severity: ErrorSeverity::Error,
373        recovery_hint: RecoveryHint::OperatorAction,
374        backtrace: BacktracePolicy::OnDemand,
375        exposure: Exposure::Generic,
376        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
377        projection: {
378            remoting: RemotingResponseCode::SystemError,
379            grpc: {
380                payload: GrpcPayloadCode::InternalError,
381                status: GrpcStatusCode::Internal,
382            },
383            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
384            cli: CliExitCode::SOFTWARE,
385        },
386    }
387    /// Transport session operation failed.
388    TRANSPORT_SESSION_FAILED {
389        code: "transport.session.failed",
390        class: ErrorClass::UNAVAILABLE,
391        condition: CanonicalCondition::Unavailable,
392        fault: FaultAttribution::Dependency,
393        component: ComponentId::TRANSPORT,
394        public_message: "Transport session operation failed",
395        severity: ErrorSeverity::Error,
396        recovery_hint: RecoveryHint::Backoff,
397        backtrace: BacktracePolicy::Never,
398        exposure: Exposure::Generic,
399        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
400        projection: {
401            remoting: RemotingResponseCode::SystemError,
402            grpc: {
403                payload: GrpcPayloadCode::InternalError,
404                status: GrpcStatusCode::Unavailable,
405            },
406            http: HttpStatusCode::SERVICE_UNAVAILABLE,
407            cli: CliExitCode::UNAVAILABLE,
408        },
409    }
410    /// Storage lifecycle operation attempted before startup completed.
411    STORAGE_LIFECYCLE_NOT_STARTED {
412        code: "storage.lifecycle.not_started",
413        class: ErrorClass::VALIDATION,
414        condition: CanonicalCondition::FailedPrecondition,
415        fault: FaultAttribution::Caller,
416        component: ComponentId::STORAGE,
417        public_message: "Storage service is not started",
418        severity: ErrorSeverity::Warn,
419        recovery_hint: RecoveryHint::Never,
420        backtrace: BacktracePolicy::Never,
421        exposure: Exposure::Public,
422        fields: [
423            fields::STORE_OPERATION,
424            fields::STORE_COMPONENT,
425            fields::STORE_DETAIL_PRESENT,
426            fields::SOURCE_PRESENT,
427        ],
428        projection: {
429            remoting: RemotingResponseCode::SystemError,
430            grpc: {
431                payload: GrpcPayloadCode::InternalError,
432                status: GrpcStatusCode::FailedPrecondition,
433            },
434            http: HttpStatusCode::CONFLICT,
435            cli: CliExitCode::DATA,
436        },
437    }
438    /// Configured storage backend is unavailable.
439    STORAGE_BACKEND_UNAVAILABLE {
440        code: "storage.backend.unavailable",
441        class: ErrorClass::UNAVAILABLE,
442        condition: CanonicalCondition::Unavailable,
443        fault: FaultAttribution::Dependency,
444        component: ComponentId::STORAGE,
445        public_message: "Storage backend is unavailable",
446        severity: ErrorSeverity::Error,
447        recovery_hint: RecoveryHint::Backoff,
448        backtrace: BacktracePolicy::Never,
449        exposure: Exposure::Generic,
450        fields: [
451            fields::STORE_OPERATION,
452            fields::STORE_COMPONENT,
453            fields::STORE_DETAIL_PRESENT,
454            fields::SOURCE_PRESENT,
455        ],
456        projection: {
457            remoting: RemotingResponseCode::SystemError,
458            grpc: {
459                payload: GrpcPayloadCode::InternalError,
460                status: GrpcStatusCode::Unavailable,
461            },
462            http: HttpStatusCode::SERVICE_UNAVAILABLE,
463            cli: CliExitCode::UNAVAILABLE,
464        },
465    }
466    /// Invalid request at the storage capability boundary.
467    STORAGE_REQUEST_INVALID {
468        code: "storage.request.invalid",
469        class: ErrorClass::VALIDATION,
470        condition: CanonicalCondition::InvalidArgument,
471        fault: FaultAttribution::Caller,
472        component: ComponentId::STORAGE,
473        public_message: "Storage request is invalid",
474        severity: ErrorSeverity::Info,
475        recovery_hint: RecoveryHint::Never,
476        backtrace: BacktracePolicy::Never,
477        exposure: Exposure::Public,
478        fields: [
479            fields::STORE_OPERATION,
480            fields::STORE_COMPONENT,
481            fields::STORE_DETAIL_PRESENT,
482            fields::SOURCE_PRESENT,
483        ],
484        projection: {
485            remoting: RemotingResponseCode::InvalidParameter,
486            grpc: {
487                payload: GrpcPayloadCode::BadRequest,
488                status: GrpcStatusCode::InvalidArgument,
489            },
490            http: HttpStatusCode::BAD_REQUEST,
491            cli: CliExitCode::USAGE,
492        },
493    }
494    /// Requested mapped file does not exist.
495    STORAGE_MAPPED_FILE_NOT_FOUND {
496        code: "storage.mapped_file.not_found",
497        class: ErrorClass::IO,
498        condition: CanonicalCondition::NotFound,
499        fault: FaultAttribution::LocalResource,
500        component: ComponentId::STORAGE,
501        public_message: "Mapped file was not found",
502        severity: ErrorSeverity::Warn,
503        recovery_hint: RecoveryHint::Never,
504        backtrace: BacktracePolicy::Never,
505        exposure: Exposure::Generic,
506        fields: [
507            fields::STORE_OPERATION,
508            fields::STORE_COMPONENT,
509            fields::STORE_DETAIL_PRESENT,
510            fields::SOURCE_PRESENT,
511        ],
512        projection: {
513            remoting: RemotingResponseCode::QueryNotFound,
514            grpc: {
515                payload: GrpcPayloadCode::NotFound,
516                status: GrpcStatusCode::NotFound,
517            },
518            http: HttpStatusCode::NOT_FOUND,
519            cli: CliExitCode::NOT_FOUND,
520        },
521    }
522    /// Storage has no remaining capacity for the operation.
523    STORAGE_CAPACITY_EXHAUSTED {
524        code: "storage.capacity.exhausted",
525        class: ErrorClass::CAPACITY,
526        condition: CanonicalCondition::ResourceExhausted,
527        fault: FaultAttribution::LocalResource,
528        component: ComponentId::STORAGE,
529        public_message: "Storage capacity is exhausted",
530        severity: ErrorSeverity::Critical,
531        recovery_hint: RecoveryHint::OperatorAction,
532        backtrace: BacktracePolicy::Never,
533        exposure: Exposure::Generic,
534        fields: [
535            fields::STORE_OPERATION,
536            fields::STORE_COMPONENT,
537            fields::STORE_DETAIL_PRESENT,
538            fields::SOURCE_PRESENT,
539        ],
540        projection: {
541            remoting: RemotingResponseCode::SystemError,
542            grpc: {
543                payload: GrpcPayloadCode::InternalError,
544                status: GrpcStatusCode::ResourceExhausted,
545            },
546            http: HttpStatusCode::INSUFFICIENT_STORAGE,
547            cli: CliExitCode::DATA,
548        },
549    }
550    /// Storage read operation failed.
551    STORAGE_READ_FAILED {
552        code: "storage.read.failed",
553        class: ErrorClass::IO,
554        condition: CanonicalCondition::Internal,
555        fault: FaultAttribution::LocalResource,
556        component: ComponentId::STORAGE,
557        public_message: "Storage read failed",
558        severity: ErrorSeverity::Error,
559        recovery_hint: RecoveryHint::OperatorAction,
560        backtrace: BacktracePolicy::Never,
561        exposure: Exposure::Generic,
562        fields: [
563            fields::STORE_OPERATION,
564            fields::STORE_COMPONENT,
565            fields::STORE_DETAIL_PRESENT,
566            fields::SOURCE_PRESENT,
567        ],
568        projection: {
569            remoting: RemotingResponseCode::SystemError,
570            grpc: {
571                payload: GrpcPayloadCode::InternalError,
572                status: GrpcStatusCode::Internal,
573            },
574            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
575            cli: CliExitCode::SOFTWARE,
576        },
577    }
578    /// Storage write operation failed.
579    STORAGE_WRITE_FAILED {
580        code: "storage.write.failed",
581        class: ErrorClass::IO,
582        condition: CanonicalCondition::Internal,
583        fault: FaultAttribution::LocalResource,
584        component: ComponentId::STORAGE,
585        public_message: "Storage write failed",
586        severity: ErrorSeverity::Error,
587        recovery_hint: RecoveryHint::OperatorAction,
588        backtrace: BacktracePolicy::Never,
589        exposure: Exposure::Generic,
590        fields: [
591            fields::STORE_OPERATION,
592            fields::STORE_COMPONENT,
593            fields::STORE_DETAIL_PRESENT,
594            fields::SOURCE_PRESENT,
595        ],
596        projection: {
597            remoting: RemotingResponseCode::SystemError,
598            grpc: {
599                payload: GrpcPayloadCode::InternalError,
600                status: GrpcStatusCode::Internal,
601            },
602            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
603            cli: CliExitCode::SOFTWARE,
604        },
605    }
606    /// Storage I/O operation failed.
607    STORAGE_IO_FAILED {
608        code: "storage.io.failed",
609        class: ErrorClass::IO,
610        condition: CanonicalCondition::Internal,
611        fault: FaultAttribution::LocalResource,
612        component: ComponentId::STORAGE,
613        public_message: "Storage I/O operation failed",
614        severity: ErrorSeverity::Error,
615        recovery_hint: RecoveryHint::OperatorAction,
616        backtrace: BacktracePolicy::Never,
617        exposure: Exposure::Generic,
618        fields: [
619            fields::STORE_OPERATION,
620            fields::STORE_COMPONENT,
621            fields::STORE_DETAIL_PRESENT,
622            fields::SOURCE_PRESENT,
623        ],
624        projection: {
625            remoting: RemotingResponseCode::SystemError,
626            grpc: {
627                payload: GrpcPayloadCode::InternalError,
628                status: GrpcStatusCode::Internal,
629            },
630            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
631            cli: CliExitCode::SOFTWARE,
632        },
633    }
634    /// Storage state is corrupted.
635    STORAGE_STATE_CORRUPTED {
636        code: "storage.state.corrupted",
637        class: ErrorClass::DATA_CORRUPTION,
638        condition: CanonicalCondition::DataLoss,
639        fault: FaultAttribution::LocalResource,
640        component: ComponentId::STORAGE,
641        public_message: "Storage state is corrupted",
642        severity: ErrorSeverity::Critical,
643        recovery_hint: RecoveryHint::OperatorAction,
644        backtrace: BacktracePolicy::OnDemand,
645        exposure: Exposure::Generic,
646        fields: [
647            fields::STORE_OPERATION,
648            fields::STORE_COMPONENT,
649            fields::STORE_DETAIL_PRESENT,
650            fields::SOURCE_PRESENT,
651        ],
652        projection: {
653            remoting: RemotingResponseCode::SystemError,
654            grpc: {
655                payload: GrpcPayloadCode::InternalError,
656                status: GrpcStatusCode::DataLoss,
657            },
658            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
659            cli: CliExitCode::DATA,
660        },
661    }
662    /// Storage operation exceeded its deadline.
663    STORAGE_OPERATION_TIMED_OUT {
664        code: "storage.operation.timed_out",
665        class: ErrorClass::TIMEOUT,
666        condition: CanonicalCondition::DeadlineExceeded,
667        fault: FaultAttribution::LocalResource,
668        component: ComponentId::STORAGE,
669        public_message: "Storage operation timed out",
670        severity: ErrorSeverity::Warn,
671        recovery_hint: RecoveryHint::Backoff,
672        backtrace: BacktracePolicy::Never,
673        exposure: Exposure::Generic,
674        fields: [
675            fields::STORE_OPERATION,
676            fields::STORE_COMPONENT,
677            fields::STORE_DETAIL_PRESENT,
678            fields::SOURCE_PRESENT,
679        ],
680        projection: {
681            remoting: RemotingResponseCode::SystemBusy,
682            grpc: {
683                payload: GrpcPayloadCode::RequestTimeout,
684                status: GrpcStatusCode::DeadlineExceeded,
685            },
686            http: HttpStatusCode::GATEWAY_TIMEOUT,
687            cli: CliExitCode::TEMPORARY_FAILURE,
688        },
689    }
690    /// Storage operation is not implemented by the backend.
691    STORAGE_OPERATION_UNSUPPORTED {
692        code: "storage.operation.unsupported",
693        class: ErrorClass::UNSUPPORTED,
694        condition: CanonicalCondition::Unimplemented,
695        fault: FaultAttribution::Configuration,
696        component: ComponentId::STORAGE,
697        public_message: "Storage operation is unsupported",
698        severity: ErrorSeverity::Error,
699        recovery_hint: RecoveryHint::Never,
700        backtrace: BacktracePolicy::Never,
701        exposure: Exposure::Public,
702        fields: [
703            fields::STORE_OPERATION,
704            fields::STORE_COMPONENT,
705            fields::STORE_DETAIL_PRESENT,
706            fields::SOURCE_PRESENT,
707        ],
708        projection: {
709            remoting: RemotingResponseCode::RequestCodeNotSupported,
710            grpc: {
711                payload: GrpcPayloadCode::Unsupported,
712                status: GrpcStatusCode::Unimplemented,
713            },
714            http: HttpStatusCode::BAD_REQUEST,
715            cli: CliExitCode::USAGE,
716        },
717    }
718    /// Internal storage failure without a more specific descriptor.
719    STORAGE_INTERNAL_FAILURE {
720        code: "storage.internal.failure",
721        class: ErrorClass::INTERNAL,
722        condition: CanonicalCondition::Internal,
723        fault: FaultAttribution::Unknown,
724        component: ComponentId::STORAGE,
725        public_message: "Internal storage failure",
726        severity: ErrorSeverity::Error,
727        recovery_hint: RecoveryHint::OperatorAction,
728        backtrace: BacktracePolicy::OnDemand,
729        exposure: Exposure::Generic,
730        fields: [
731            fields::STORE_OPERATION,
732            fields::STORE_COMPONENT,
733            fields::STORE_DETAIL_PRESENT,
734            fields::SOURCE_PRESENT,
735        ],
736        projection: {
737            remoting: RemotingResponseCode::SystemError,
738            grpc: {
739                payload: GrpcPayloadCode::InternalError,
740                status: GrpcStatusCode::Internal,
741            },
742            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
743            cli: CliExitCode::SOFTWARE,
744        },
745    }
746    /// Protocol version that this implementation does not support.
747    PROTOCOL_VERSION_UNSUPPORTED {
748        code: "protocol.version.unsupported",
749        class: ErrorClass::UNSUPPORTED,
750        condition: CanonicalCondition::Unimplemented,
751        fault: FaultAttribution::Caller,
752        component: ComponentId::PROTOCOL,
753        public_message: "Protocol version is unsupported",
754        severity: ErrorSeverity::Error,
755        recovery_hint: RecoveryHint::Never,
756        backtrace: BacktracePolicy::Never,
757        exposure: Exposure::Public,
758        fields: [fields::ORDINAL],
759        projection: {
760            remoting: RemotingResponseCode::RequestCodeNotSupported,
761            grpc: {
762                payload: GrpcPayloadCode::Unsupported,
763                status: GrpcStatusCode::Unimplemented,
764            },
765            http: HttpStatusCode::BAD_REQUEST,
766            cli: CliExitCode::USAGE,
767        },
768    }
769    /// Internal failure without a more specific catalog identity.
770    CORE_INTERNAL_FAILURE {
771        code: "core.internal.failure",
772        class: ErrorClass::INTERNAL,
773        condition: CanonicalCondition::Internal,
774        fault: FaultAttribution::Unknown,
775        component: ComponentId::CORE,
776        public_message: "Internal error",
777        severity: ErrorSeverity::Error,
778        recovery_hint: RecoveryHint::OperatorAction,
779        backtrace: BacktracePolicy::OnDemand,
780        exposure: Exposure::Generic,
781        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
782        projection: {
783            remoting: RemotingResponseCode::SystemError,
784            grpc: {
785                payload: GrpcPayloadCode::InternalError,
786                status: GrpcStatusCode::Internal,
787            },
788            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
789            cli: CliExitCode::SOFTWARE,
790        },
791    }
792    /// Runtime configuration could not be loaded or interpreted.
793    RUNTIME_CONFIGURATION_FAILED {
794        code: "runtime.configuration.failed",
795        class: ErrorClass::VALIDATION,
796        condition: CanonicalCondition::InvalidArgument,
797        fault: FaultAttribution::Configuration,
798        component: ComponentId::RUNTIME,
799        public_message: "Runtime configuration is invalid",
800        severity: ErrorSeverity::Info,
801        recovery_hint: RecoveryHint::Never,
802        backtrace: BacktracePolicy::Never,
803        exposure: Exposure::Public,
804        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
805        projection: {
806            remoting: RemotingResponseCode::InvalidParameter,
807            grpc: {
808                payload: GrpcPayloadCode::BadRequest,
809                status: GrpcStatusCode::InvalidArgument,
810            },
811            http: HttpStatusCode::BAD_REQUEST,
812            cli: CliExitCode::CONFIG,
813        },
814    }
815    /// Runtime construction failed.
816    RUNTIME_BUILD_FAILED {
817        code: "runtime.build.failed",
818        class: ErrorClass::UNAVAILABLE,
819        condition: CanonicalCondition::Unavailable,
820        fault: FaultAttribution::Configuration,
821        component: ComponentId::RUNTIME,
822        public_message: "Runtime could not be started",
823        severity: ErrorSeverity::Error,
824        recovery_hint: RecoveryHint::OperatorAction,
825        backtrace: BacktracePolicy::Never,
826        exposure: Exposure::Generic,
827        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
828        projection: {
829            remoting: RemotingResponseCode::SystemError,
830            grpc: {
831                payload: GrpcPayloadCode::InternalError,
832                status: GrpcStatusCode::Unavailable,
833            },
834            http: HttpStatusCode::SERVICE_UNAVAILABLE,
835            cli: CliExitCode::UNAVAILABLE,
836        },
837    }
838    /// Runtime I/O failed.
839    RUNTIME_IO_FAILED {
840        code: "runtime.io.failed",
841        class: ErrorClass::IO,
842        condition: CanonicalCondition::Internal,
843        fault: FaultAttribution::LocalResource,
844        component: ComponentId::RUNTIME,
845        public_message: "Runtime I/O operation failed",
846        severity: ErrorSeverity::Error,
847        recovery_hint: RecoveryHint::OperatorAction,
848        backtrace: BacktracePolicy::Never,
849        exposure: Exposure::Generic,
850        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
851        projection: {
852            remoting: RemotingResponseCode::SystemError,
853            grpc: {
854                payload: GrpcPayloadCode::InternalError,
855                status: GrpcStatusCode::Internal,
856            },
857            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
858            cli: CliExitCode::SOFTWARE,
859        },
860    }
861    /// A required Tokio runtime context is unavailable.
862    RUNTIME_CONTEXT_UNAVAILABLE {
863        code: "runtime.context.unavailable",
864        class: ErrorClass::UNAVAILABLE,
865        condition: CanonicalCondition::Unavailable,
866        fault: FaultAttribution::LocalResource,
867        component: ComponentId::RUNTIME,
868        public_message: "Runtime context is unavailable",
869        severity: ErrorSeverity::Error,
870        recovery_hint: RecoveryHint::Never,
871        backtrace: BacktracePolicy::Never,
872        exposure: Exposure::Generic,
873        fields: [fields::OPERATION_DIAGNOSTIC],
874        projection: {
875            remoting: RemotingResponseCode::SystemError,
876            grpc: {
877                payload: GrpcPayloadCode::InternalError,
878                status: GrpcStatusCode::Unavailable,
879            },
880            http: HttpStatusCode::SERVICE_UNAVAILABLE,
881            cli: CliExitCode::UNAVAILABLE,
882        },
883    }
884    /// Runtime capacity needed by an operational path is exhausted.
885    RUNTIME_CAPACITY_EXHAUSTED {
886        code: "runtime.capacity.exhausted",
887        class: ErrorClass::CAPACITY,
888        condition: CanonicalCondition::ResourceExhausted,
889        fault: FaultAttribution::LocalResource,
890        component: ComponentId::RUNTIME,
891        public_message: "Runtime capacity is exhausted",
892        severity: ErrorSeverity::Warn,
893        recovery_hint: RecoveryHint::Backoff,
894        backtrace: BacktracePolicy::Never,
895        exposure: Exposure::Generic,
896        fields: [fields::OPERATION_DIAGNOSTIC],
897        projection: {
898            remoting: RemotingResponseCode::SystemBusy,
899            grpc: {
900                payload: GrpcPayloadCode::TooManyRequests,
901                status: GrpcStatusCode::ResourceExhausted,
902            },
903            http: HttpStatusCode::TOO_MANY_REQUESTS,
904            cli: CliExitCode::TEMPORARY_FAILURE,
905        },
906    }
907    /// A runtime operation exceeded its deadline.
908    RUNTIME_OPERATION_TIMED_OUT {
909        code: "runtime.operation.timed_out",
910        class: ErrorClass::TIMEOUT,
911        condition: CanonicalCondition::DeadlineExceeded,
912        fault: FaultAttribution::Dependency,
913        component: ComponentId::RUNTIME,
914        public_message: "Runtime operation timed out",
915        severity: ErrorSeverity::Warn,
916        recovery_hint: RecoveryHint::Backoff,
917        backtrace: BacktracePolicy::Never,
918        exposure: Exposure::Generic,
919        fields: [fields::OPERATION_DIAGNOSTIC],
920        projection: {
921            remoting: RemotingResponseCode::SystemBusy,
922            grpc: {
923                payload: GrpcPayloadCode::RequestTimeout,
924                status: GrpcStatusCode::DeadlineExceeded,
925            },
926            http: HttpStatusCode::GATEWAY_TIMEOUT,
927            cli: CliExitCode::TEMPORARY_FAILURE,
928        },
929    }
930    /// A runtime operation is unsupported.
931    RUNTIME_OPERATION_UNSUPPORTED {
932        code: "runtime.operation.unsupported",
933        class: ErrorClass::UNSUPPORTED,
934        condition: CanonicalCondition::Unimplemented,
935        fault: FaultAttribution::Caller,
936        component: ComponentId::RUNTIME,
937        public_message: "Runtime operation is unsupported",
938        severity: ErrorSeverity::Error,
939        recovery_hint: RecoveryHint::Never,
940        backtrace: BacktracePolicy::Never,
941        exposure: Exposure::Public,
942        fields: [fields::OPERATION_DIAGNOSTIC],
943        projection: {
944            remoting: RemotingResponseCode::RequestCodeNotSupported,
945            grpc: {
946                payload: GrpcPayloadCode::Unsupported,
947                status: GrpcStatusCode::Unimplemented,
948            },
949            http: HttpStatusCode::BAD_REQUEST,
950            cli: CliExitCode::USAGE,
951        },
952    }
953    /// A runtime task could not be joined.
954    RUNTIME_TASK_JOIN_FAILED {
955        code: "runtime.task.join_failed",
956        class: ErrorClass::BUG,
957        condition: CanonicalCondition::Internal,
958        fault: FaultAttribution::Bug,
959        component: ComponentId::RUNTIME,
960        public_message: "Runtime task failed",
961        severity: ErrorSeverity::Error,
962        recovery_hint: RecoveryHint::OperatorAction,
963        backtrace: BacktracePolicy::OnDemand,
964        exposure: Exposure::Generic,
965        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
966        projection: {
967            remoting: RemotingResponseCode::SystemError,
968            grpc: {
969                payload: GrpcPayloadCode::InternalError,
970                status: GrpcStatusCode::Internal,
971            },
972            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
973            cli: CliExitCode::SOFTWARE,
974        },
975    }
976    /// An internal runtime failure occurred.
977    RUNTIME_INTERNAL_FAILURE {
978        code: "runtime.internal.failure",
979        class: ErrorClass::INTERNAL,
980        condition: CanonicalCondition::Internal,
981        fault: FaultAttribution::Unknown,
982        component: ComponentId::RUNTIME,
983        public_message: "Runtime operation failed",
984        severity: ErrorSeverity::Error,
985        recovery_hint: RecoveryHint::OperatorAction,
986        backtrace: BacktracePolicy::OnDemand,
987        exposure: Exposure::Generic,
988        fields: [fields::OPERATION_DIAGNOSTIC, fields::SOURCE_PRESENT],
989        projection: {
990            remoting: RemotingResponseCode::SystemError,
991            grpc: {
992                payload: GrpcPayloadCode::InternalError,
993                status: GrpcStatusCode::Internal,
994            },
995            http: HttpStatusCode::INTERNAL_SERVER_ERROR,
996            cli: CliExitCode::SOFTWARE,
997        },
998    }
999}
1000
1001/// Every canonical descriptor currently declared by `rocketmq-error`.
1002///
1003/// This is the sole iterable catalog authority used by exact-code lookup.
1004pub const ALL_DESCRIPTORS: &[ErrorDescriptor] = &[
1005    PROTOCOL_HEADER_INVALID,
1006    ROUTE_TOPIC_NOT_FOUND,
1007    AUTH_CREDENTIALS_INVALID,
1008    AUTH_USER_NOT_FOUND,
1009    AUTH_PERMISSION_DENIED,
1010    TRANSPORT_ADMISSION_QUEUE_SATURATED,
1011    CONTROLLER_LEADERSHIP_NOT_LEADER,
1012    TRANSPORT_CONNECTION_TIMEOUT,
1013    TRANSPORT_START_FAILED,
1014    TRANSPORT_DISPATCH_FAILED,
1015    TRANSPORT_RESPONSE_FAILED,
1016    TRANSPORT_SESSION_FAILED,
1017    STORAGE_LIFECYCLE_NOT_STARTED,
1018    STORAGE_BACKEND_UNAVAILABLE,
1019    STORAGE_REQUEST_INVALID,
1020    STORAGE_MAPPED_FILE_NOT_FOUND,
1021    STORAGE_CAPACITY_EXHAUSTED,
1022    STORAGE_READ_FAILED,
1023    STORAGE_WRITE_FAILED,
1024    STORAGE_IO_FAILED,
1025    STORAGE_STATE_CORRUPTED,
1026    STORAGE_OPERATION_TIMED_OUT,
1027    STORAGE_OPERATION_UNSUPPORTED,
1028    STORAGE_INTERNAL_FAILURE,
1029    PROTOCOL_VERSION_UNSUPPORTED,
1030    CORE_INTERNAL_FAILURE,
1031    RUNTIME_CONFIGURATION_FAILED,
1032    RUNTIME_BUILD_FAILED,
1033    RUNTIME_IO_FAILED,
1034    RUNTIME_CONTEXT_UNAVAILABLE,
1035    RUNTIME_CAPACITY_EXHAUSTED,
1036    RUNTIME_OPERATION_TIMED_OUT,
1037    RUNTIME_OPERATION_UNSUPPORTED,
1038    RUNTIME_TASK_JOIN_FAILED,
1039    RUNTIME_INTERNAL_FAILURE,
1040    TRANSPORT_ENDPOINT_INVALID,
1041    TRANSPORT_REMOTE_RATE_LIMITED,
1042    TRANSPORT_WRITE_TIMEOUT,
1043    TRANSPORT_RESPONSE_TIMEOUT,
1044    TRANSPORT_DNS_FAILED,
1045    TRANSPORT_CONNECTION_FAILED,
1046    CORE_SERIALIZATION_FAILED,
1047    PROTOCOL_BODY_INVALID,
1048    PROTOCOL_ENCODING_UNSUPPORTED,
1049    PROTOCOL_REQUEST_UNSUPPORTED,
1050    PROXY_BROKER_PERMISSION_DENIED,
1051    PROXY_BROKER_TOPIC_NOT_FOUND,
1052    PROXY_BROKER_CONSUMER_GROUP_NOT_FOUND,
1053    PROXY_BROKER_RESOURCE_NOT_FOUND,
1054    PROXY_BROKER_OFFSET_NOT_FOUND,
1055    PROXY_BROKER_OFFSET_INVALID,
1056    PROXY_BROKER_REQUEST_UNSUPPORTED,
1057    PROXY_BROKER_RESPONSE_FAILED,
1058    PROXY_CLIENT_ID_REQUIRED,
1059    PROXY_CLIENT_TYPE_UNRECOGNIZED,
1060    PROXY_CAPABILITY_UNSUPPORTED,
1061    PROXY_CAPACITY_EXHAUSTED,
1062    PROXY_REQUEST_DRAINING,
1063    PROXY_METADATA_INVALID,
1064    PROXY_TRANSPORT_UNAVAILABLE,
1065    PROXY_MESSAGE_ID_INVALID,
1066    PROXY_TRANSACTION_ID_INVALID,
1067    PROXY_MESSAGE_GROUP_INVALID,
1068    PROXY_DELIVERY_TIME_INVALID,
1069    PROXY_POLLING_TIME_INVALID,
1070    PROXY_OFFSET_INVALID,
1071    PROXY_INVISIBLE_TIME_INVALID,
1072    PROXY_FILTER_EXPRESSION_INVALID,
1073    PROXY_RECEIPT_HANDLE_INVALID,
1074    PROXY_LITE_TOPIC_INVALID,
1075    PROXY_LITE_SUBSCRIPTION_QUOTA_EXCEEDED,
1076    PROXY_MESSAGE_PROPERTY_CONFLICT,
1077    PROXY_SETTINGS_UNAVAILABLE,
1078    PROXY_REMOTING_REQUEST_INVALID,
1079    PROXY_UPSTREAM_REQUEST_FAILED,
1080    PROXY_DRAIN_UNAVAILABLE,
1081    RPC_BROKER_ADDRESS_NOT_FOUND,
1082    RPC_REQUEST_UNSUPPORTED,
1083    AUTH_OPERATION_FAILED,
1084    SECURITY_PROVIDER_NOT_FOUND,
1085    SECURITY_PROVIDER_CONFLICT,
1086    SECURITY_PROVIDER_UNSUPPORTED,
1087    SECURITY_PROVIDER_INVALID_DATA,
1088    SECURITY_PROVIDER_CONTRACT_VIOLATION,
1089    SECURITY_PROVIDER_UNAVAILABLE,
1090    SECURITY_PROVIDER_OPERATION_FAILED,
1091    CONTROLLER_INTERNAL_FAILURE,
1092    CONTROLLER_REQUEST_INVALID,
1093    CONTROLLER_CONFIGURATION_INVALID,
1094    CONTROLLER_LIFECYCLE_NOT_INITIALIZED,
1095    PROTOCOL_MESSAGE_PROPERTY_INVALID,
1096    BROKER_LOOKUP_NOT_FOUND,
1097    BROKER_REGISTRATION_FAILED,
1098    BROKER_OPERATION_FAILED,
1099    BROKER_TOPIC_NOT_FOUND,
1100    BROKER_QUEUE_NOT_FOUND,
1101    BROKER_SUBSCRIPTION_GROUP_NOT_FOUND,
1102    BROKER_QUEUE_ID_OUT_OF_RANGE,
1103    BROKER_MESSAGE_TOO_LARGE,
1104    BROKER_MESSAGE_INVALID,
1105    CLIENT_RETRY_BUDGET_EXHAUSTED,
1106    BROKER_TRANSACTION_REJECTED,
1107    BROKER_LEADERSHIP_NOT_MASTER,
1108    BROKER_QUERY_NOT_FOUND,
1109    BROKER_TASK_FAILED,
1110    PROTOCOL_RESPONSE_FAILED,
1111    ROUTE_TOPIC_INCONSISTENT,
1112    ROUTE_REGISTRATION_CONFLICT,
1113    ROUTE_CLUSTER_NOT_FOUND,
1114    CLIENT_LIFECYCLE_NOT_STARTED,
1115    CLIENT_LIFECYCLE_ALREADY_STARTED,
1116    CLIENT_LIFECYCLE_SHUTTING_DOWN,
1117    CLIENT_LIFECYCLE_INVALID_STATE,
1118    CLIENT_COMPONENT_UNAVAILABLE,
1119    RPC_REQUEST_FAILED,
1120    RPC_RESPONSE_FAILED,
1121    TOOLS_OPERATION_FAILED,
1122    PROTOCOL_FILTER_INVALID,
1123    OBSERVABILITY_FEATURE_DISABLED,
1124    OBSERVABILITY_CONFIGURATION_INVALID,
1125    OBSERVABILITY_INITIALIZATION_FAILED,
1126    OBSERVABILITY_LOG_FILTER_INVALID,
1127    OBSERVABILITY_SUBSCRIBER_INSTALLATION_FAILED,
1128    OBSERVABILITY_SHUTDOWN_FAILED,
1129    CORE_CONFIGURATION_PARSE_FAILED,
1130    CORE_CONFIGURATION_MISSING,
1131    CORE_CONFIGURATION_INVALID,
1132    AUTH_CONFIGURATION_INVALID,
1133    AUTH_CONFIGURATION_RELOAD_FAILED,
1134    CONTROLLER_CONSENSUS_FAILED,
1135    CONTROLLER_CONSENSUS_TIMED_OUT,
1136    CORE_IO_FAILED,
1137    CORE_ARGUMENT_INVALID,
1138    CORE_OPERATION_TIMED_OUT,
1139    CORE_SERVICE_FAILED,
1140    CORE_LIFECYCLE_NOT_INITIALIZED,
1141];
1142
1143/// Returns the registered descriptor for `code`.
1144///
1145/// Lookup accepts exact canonical dotted codes only. Unknown, malformed, and
1146/// transitional upper-case codes return [`None`].
1147#[inline]
1148pub fn descriptor_by_code(code: &str) -> Option<&'static ErrorDescriptor> {
1149    ALL_DESCRIPTORS
1150        .iter()
1151        .find(|descriptor| descriptor.code().as_str() == code)
1152}