Skip to content

Commit

Permalink
networks: Show an informative error message if the selected feature s…
Browse files Browse the repository at this point in the history
…et 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.
  • Loading branch information
lemmih authored Jan 14, 2022
1 parent 08891fd commit 5a85338
Showing 1 changed file with 45 additions and 24 deletions.
69 changes: 45 additions & 24 deletions types/networks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5a85338

Please sign in to comment.