flowlog_build/build/error.rs
1//! Library-mode build-flow errors.
2//!
3//! [`BuildError`] covers infrastructure and input-validation failures
4//! raised while driving a `build.rs` compilation. Pipeline-stage errors
5//! (parse / stratify / plan / codegen) flow through this crate as their
6//! own [`Diagnostic`] types inside a [`crate::common::BoxError`]; they
7//! don't round-trip through `BuildError`.
8
9use std::io;
10
11use crate::common::Diagnostic;
12use crate::common::FileId;
13use codespan_reporting::diagnostic::Diagnostic as CsDiagnostic;
14use thiserror::Error;
15
16/// Infrastructure failure raised by the library-mode build flow.
17///
18/// Surfaces filesystem I/O against `$OUT_DIR`, `OUT_DIR` lookup failures,
19/// and input-validation rejections (malformed program paths) the builder
20/// catches before handing off to the pipeline. Distinct from:
21///
22/// - [`crate::CodegenError`] — user-source errors caught during codegen.
23/// - [`crate::common::InternalError`] — compiler invariant violations
24/// that render as "please file a bug" ICEs.
25///
26/// [`Diagnostic::is_internal`] returns `false` for every `BuildError`
27/// variant, so a top-level renderer (e.g. [`crate::common::emit_and_exit`])
28/// exits with code `1` and omits the bug-report note — the user fixes
29/// their build setup, not their `.dl` program.
30#[non_exhaustive]
31#[derive(Debug, Error)]
32pub enum BuildError {
33 /// An [`io::Error`] surfaced by the build pipeline. Covers genuine
34 /// I/O (writes to `$OUT_DIR`, `OUT_DIR` lookup) as well as
35 /// input-validation rejections wrapped as
36 /// [`io::ErrorKind::InvalidInput`] — e.g. a program path with no
37 /// usable file stem or non-UTF-8 bytes.
38 #[error("{0}")]
39 Io(#[from] io::Error),
40}
41
42impl Diagnostic for BuildError {
43 fn to_diagnostic(&self) -> CsDiagnostic<FileId> {
44 CsDiagnostic::error().with_message(self.to_string())
45 }
46}