forge/diagnostic.rs
1//! Stable, machine-readable diagnostic codes emitted by `forge`.
2//!
3//! See [`docs/agents/diagnostics.md`](../../../docs/agents/diagnostics.md)
4//! for the format and registry rules. Most codes re-export per-domain
5//! constants from [`foundry_cli::diagnostic`].
6
7/// Build-time diagnostic codes (compilation, linking, artifact generation).
8pub mod build {
9 pub use foundry_cli::diagnostic::compiler::SOLC_ERROR;
10
11 pub(crate) const ALL: &[&str] = &[SOLC_ERROR];
12}
13
14/// `forge test` diagnostic codes.
15pub mod test {
16 pub use foundry_cli::diagnostic::test::{FAILED, SETUP_FAILED, WARNING};
17
18 pub(crate) const ALL: &[&str] = &[FAILED, SETUP_FAILED, WARNING];
19}
20
21/// All diagnostic codes declared by `forge`.
22pub fn known_codes() -> Vec<&'static str> {
23 let groups: &[&[&str]] = &[build::ALL, test::ALL];
24 groups.iter().flat_map(|g| g.iter().copied()).collect()
25}
26
27#[cfg(test)]
28mod tests {
29 use super::*;
30 use foundry_cli::diagnostic::validate;
31
32 #[test]
33 fn every_known_code_validates() {
34 for c in known_codes() {
35 assert!(validate(c).is_ok(), "registered code `{c}` failed validation");
36 }
37 }
38}