Skip to main content

rocketmq_model/
model_contract_violation.rs

1// Copyright 2026 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 rocketmq_error::CanonicalCondition;
16use thiserror::Error;
17
18/// Deterministic validation failure at the runtime-neutral model boundary.
19///
20/// The public messages are fixed. Variant fields retain only static schema
21/// identifiers and numeric admission evidence.
22#[derive(Clone, Debug, Error, PartialEq, Eq)]
23pub enum ModelContractViolation {
24    /// A topic-creation attribute operation did not use the add form.
25    #[error("topic creation attribute operation must use the add form")]
26    AttributeCreateRequiresAdd,
27    /// An attribute delete operation named a key that is not present.
28    #[error("attribute delete operation targets a missing key")]
29    AttributeDeleteTargetsMissingKey,
30    /// An attribute operation key did not have a supported form.
31    #[error("attribute operation key has an unsupported form")]
32    AttributeOperationKeyHasUnsupportedForm,
33    /// An attribute operation set contains the same key more than once.
34    #[error("attribute operation set contains a duplicate key")]
35    AttributeOperationSetContainsDuplicateKey,
36    /// An attribute operation key is structurally invalid.
37    #[error("attribute operation key is invalid")]
38    AttributeOperationKeyIsInvalid,
39    /// An attribute operation named an unsupported key.
40    #[error("attribute operation targets an unsupported key")]
41    AttributeOperationTargetsUnsupportedKey,
42    /// An attribute update targeted an immutable attribute.
43    #[error("attribute update targets an immutable attribute")]
44    AttributeUpdateTargetsImmutableAttribute,
45    /// An attribute value does not satisfy the selected attribute's rules.
46    #[error("attribute value does not satisfy the attribute rules")]
47    AttributeValueDoesNotSatisfyRules,
48    /// A cleanup-policy parser input did not name a supported policy.
49    #[error("cleanup policy is invalid")]
50    InvalidCleanupPolicy,
51    /// A consume-queue type parser input did not name a supported type.
52    #[error("consume queue type is invalid")]
53    InvalidCqType,
54    /// A timer request did not specify a supported delivery property.
55    #[error("timer request does not contain a supported delivery property")]
56    MissingTimerDeliveryProperty,
57    /// A timer property does not contain an unsigned integer.
58    #[error("timer property has an invalid unsigned integer value")]
59    InvalidTimerProperty {
60        /// Name of the selected timer property.
61        property: &'static str,
62    },
63    /// A timer precision is not supported by the Java-compatible timer engine.
64    #[error("timer precision is unsupported")]
65    UnsupportedTimerPrecision {
66        /// Requested timer precision in milliseconds.
67        precision_ms: u64,
68    },
69    /// Checked timer-delivery arithmetic overflowed.
70    #[error("timer delivery time arithmetic overflowed")]
71    TimerDeliveryArithmeticOverflow,
72    /// A timer delivery timestamp is not later than the caller's clock sample.
73    #[error("timer delivery time is not in the future")]
74    TimerDeliveryTimeIsNotInFuture {
75        /// Requested delivery timestamp in milliseconds.
76        deliver_ms: u64,
77        /// Caller-supplied current timestamp in milliseconds.
78        now_ms: u64,
79    },
80    /// A timer delay exceeds the configured admission horizon.
81    #[error("timer delay exceeds the configured maximum")]
82    TimerDelayExceedsMaximum {
83        /// Requested delay in milliseconds.
84        delay_ms: u64,
85        /// Configured maximum delay in milliseconds.
86        max_delay_ms: u64,
87    },
88    /// A POP retry policy does not describe a supported migration state.
89    #[error("POP retry policy does not describe a supported migration state")]
90    InvalidPopRetryPolicyState,
91}
92
93impl ModelContractViolation {
94    /// Returns the canonical condition for every model contract rejection.
95    #[inline]
96    pub const fn condition(&self) -> CanonicalCondition {
97        CanonicalCondition::InvalidArgument
98    }
99}