From 5a8533845014502f2e8f9120d4ea377bbaf87cfd Mon Sep 17 00:00:00 2001 From: David Himmelstrup Date: Fri, 14 Jan 2022 15:46:35 +0000 Subject: [PATCH] networks: Show an informative error message if the selected feature set is invalid. (#1373) * Use a descritive error message if the selected feature set is invalid. * Fix formatting. * Exactly one feature must be enabled for the 'networks' crate. --- types/networks/src/lib.rs | 69 +++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/types/networks/src/lib.rs b/types/networks/src/lib.rs index 0d5b22888e7b..a2b93760f9d1 100644 --- a/types/networks/src/lib.rs +++ b/types/networks/src/lib.rs @@ -10,41 +10,62 @@ use fil_types::NetworkVersion; use std::{error::Error, sync::Arc}; mod drand; -#[cfg(feature = "mainnet")] -mod mainnet; -#[cfg(feature = "mainnet")] -pub use self::mainnet::*; - -#[cfg(feature = "conformance")] -mod mainnet; -#[cfg(feature = "conformace")] -pub use self::mainnet::*; -pub use crate::mainnet::*; - #[cfg(all( - feature = "interopnet", + not(feature = "interopnet"), not(feature = "devnet"), - not(feature = "mainnet") + not(feature = "mainnet"), + not(feature = "conformance"), ))] -mod interopnet; +compile_error!( + "No network feature selected. Exactly one of \"mainnet\", \"devnet\", \"interopnet\", or \"conformance\" must be enabled for this crate." +); + #[cfg(all( - feature = "interopnet", - not(feature = "devnet"), - not(feature = "mainnet") + feature = "mainnet", + any(feature = "interopnet", feature = "devnet", feature = "conformance",) ))] -pub use self::interopnet::*; +compile_error!( + "\"mainnet\" feature cannot be combined with \"devnet\", \"interopnet\", or \"conformance\"." +); #[cfg(all( - feature = "devnet", - not(feature = "interopnet"), - not(feature = "mainnet") + feature = "conformance", + any(feature = "interopnet", feature = "devnet", feature = "mainnet",) ))] -mod devnet; +compile_error!( + "\"conformance\" feature cannot be combined with \"devnet\", \"interopnet\", or \"mainnet\"." +); + #[cfg(all( feature = "devnet", - not(feature = "interopnet"), - not(feature = "mainnet") + any(feature = "interopnet", feature = "conformance", feature = "mainnet",) +))] +compile_error!( + "\"devnet\" feature cannot be combined with \"conformance\", \"interopnet\", or \"mainnet\"." +); + +#[cfg(all( + feature = "interopnet", + any(feature = "conformance", feature = "devnet", feature = "mainnet",) ))] +compile_error!( + "\"interopnet\" feature cannot be combined with \"devnet\", \"conformance\", or \"mainnet\"." +); + +// Both mainnet and conformance parameters are kept in the 'mainnet' module. +#[cfg(any(feature = "mainnet", feature = "conformance"))] +mod mainnet; +#[cfg(any(feature = "mainnet", feature = "conformance"))] +pub use self::mainnet::*; + +#[cfg(feature = "interopnet")] +mod interopnet; +#[cfg(feature = "interopnet")] +pub use self::interopnet::*; + +#[cfg(feature = "devnet")] +mod devnet; +#[cfg(feature = "devnet")] pub use self::devnet::*; /// Defines the different hard fork parameters.