zerodds_idl_python/error.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! Error family for the `zerodds-idl-python` codegen.
5
6use core::fmt;
7
8/// Codegen error while emitting Python code.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum IdlPythonError {
11 /// IDL construct outside the supported Python mapping scope
12 /// (e.g. bitmask, map, fixed, any, valuetype, interface). Phase-2
13 /// material.
14 Unsupported(String),
15 /// Language-map conflict: an IDL identifier collides with a
16 /// Python reserved word and the configured escape mode would
17 /// cause two different IDL names to yield the same Python
18 /// name.
19 NameConflict(String),
20}
21
22impl fmt::Display for IdlPythonError {
23 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24 match self {
25 Self::Unsupported(msg) => write!(f, "unsupported IDL construct: {msg}"),
26 Self::NameConflict(msg) => write!(f, "python name conflict: {msg}"),
27 }
28 }
29}
30
31impl std::error::Error for IdlPythonError {}
32
33/// Specialized `Result` for codegen calls.
34pub type Result<T> = core::result::Result<T, IdlPythonError>;