proto_build_kit/errors.rs
1// SPDX-License-Identifier: MIT
2
3/// Errors surfaced by the `proto-build-kit` primitives.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6 /// I/O failure (tempdir creation, file write, parent-dir mkdir).
7 #[error("io: {0}")]
8 Io(#[from] std::io::Error),
9
10 /// `Stager::stage()` detected two entries writing to the same
11 /// protoc-relative path.
12 #[error("duplicate proto staged at {path:?}")]
13 DuplicatePath {
14 /// The relative path declared twice.
15 path: String,
16 },
17
18 /// `protox` failed to parse one of the `.proto` files.
19 #[error("protox compile: {0}")]
20 Protox(#[from] Box<protox::Error>),
21
22 /// `prost-reflect` descriptor-pool construction failed.
23 #[error("descriptor pool: {0}")]
24 DescriptorPool(#[from] prost_reflect::DescriptorError),
25
26 /// `tonic-prost-build` codegen failed (only surfaced when the
27 /// `tonic` feature is enabled).
28 #[cfg(feature = "tonic")]
29 #[error("tonic-build codegen: {0}")]
30 Tonic(#[source] Box<dyn std::error::Error + Send + Sync>),
31}
32
33// `protox::Error` is large; box it to keep the enum cheap to move.
34impl From<protox::Error> for Error {
35 fn from(e: protox::Error) -> Self {
36 Error::Protox(Box::new(e))
37 }
38}