Skip to content

Commit

Permalink
chore(errors): hide the TooManyFunctions error variant behind a featu…
Browse files Browse the repository at this point in the history
…re flag (#5052)

Context: #5042 (comment)

Hides the `TooManyFunctions` error variant behind a feature gate to avoid it leaking into the `rpc_errors_schema.json` dump.
  • Loading branch information
miraclx authored Oct 21, 2021
1 parent 2a3747e commit 4c98e20
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions runtime/near-vm-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ near-rpc-error-macro = { path = "../../tools/rpctypegen/macro", version = "0.1.0
[features]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_alt_bn128 = []
protocol_feature_limit_contract_functions_number = []

[package.metadata.workspaces]
independent = true
2 changes: 2 additions & 0 deletions runtime/near-vm-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub enum PrepareError {
/// Error creating memory.
Memory,
/// Contract contains too many functions.
#[cfg(feature = "protocol_feature_limit_contract_functions_number")]
TooManyFunctions,
}

Expand Down Expand Up @@ -293,6 +294,7 @@ impl fmt::Display for PrepareError {
StackHeightInstrumentation => write!(f, "Stack instrumentation failed."),
Instantiate => write!(f, "Error happened during instantiation."),
Memory => write!(f, "Error creating memory."),
#[cfg(feature = "protocol_feature_limit_contract_functions_number")]
TooManyFunctions => write!(f, "Too many functions in contract."),
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protocol_feature_alt_bn128 = [
"near-primitives/protocol_feature_alt_bn128",
"near-vm-errors/protocol_feature_alt_bn128"
]
protocol_feature_limit_contract_functions_number = ["near-primitives/protocol_feature_limit_contract_functions_number"]
protocol_feature_limit_contract_functions_number = ["near-primitives/protocol_feature_limit_contract_functions_number", "near-vm-errors/protocol_feature_limit_contract_functions_number"]
nightly_protocol = ["near-primitives/nightly_protocol"]

[package.metadata.cargo-udeps.ignore]
Expand Down
20 changes: 10 additions & 10 deletions runtime/near-vm-runner/src/tests/compile_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use near_primitives::version::ProtocolFeature;
use near_primitives::version::PROTOCOL_VERSION;
use near_vm_errors::{CompilationError, FunctionCallError, PrepareError, VMError};

#[cfg(feature = "protocol_feature_limit_contract_functions_number")]
use assert_matches::assert_matches;

use crate::tests::{
Expand Down Expand Up @@ -191,15 +192,14 @@ fn test_limit_contract_functions_number() {
new_protocol_version,
vm_kind,
);
if cfg!(feature = "protocol_feature_limit_contract_functions_number") {
assert_matches!(
err,
Some(VMError::FunctionCallError(FunctionCallError::CompilationError(
CompilationError::PrepareError(PrepareError::TooManyFunctions)
)))
);
} else {
assert_eq!(err, None);
}
#[cfg(not(feature = "protocol_feature_limit_contract_functions_number"))]
assert_eq!(err, None);
#[cfg(feature = "protocol_feature_limit_contract_functions_number")]
assert_matches!(
err,
Some(VMError::FunctionCallError(FunctionCallError::CompilationError(
CompilationError::PrepareError(PrepareError::TooManyFunctions)
)))
);
});
}

0 comments on commit 4c98e20

Please sign in to comment.