Skip to content

Commit 59cb8ff

Browse files
Remove ExpectsAcceptable option
Signed-off-by: Jacinta Ferrant <jacinta@stackslabs.com>
1 parent b8ca7dd commit 59cb8ff

File tree

19 files changed

+135
-198
lines changed

19 files changed

+135
-198
lines changed

clarity-types/src/errors/analysis.rs

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,7 @@ pub enum CommonCheckErrorKind {
200200
// Unexpected interpreter behavior
201201
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
202202
/// This error indicates a transaction would invalidate a block if included.
203-
ExpectsRejectable(String),
204-
// Unexpected interpreter behavior
205-
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
206-
/// This error does NOT indicate a transaction would invalidate a block if included.
207-
ExpectsAcceptable(String),
203+
Expects(String),
208204

209205
// Type mismatch errors
210206
/// Expected type does not match the actual type during analysis.
@@ -293,24 +289,16 @@ impl CommonCheckErrorKind {
293289
| ClarityTypeError::QualifiedContractMissingDot
294290
| ClarityTypeError::InvalidPrincipalEncoding(_)
295291
| ClarityTypeError::InvalidPrincipalLength(_)
296-
| ClarityTypeError::ResponseTypeMismatch { .. } => {
297-
CommonCheckErrorKind::ExpectsAcceptable(format!(
298-
"Unexpected error type during analysis: {err}"
299-
))
300-
}
301-
ClarityTypeError::InvariantViolation(_)
292+
| ClarityTypeError::ResponseTypeMismatch { .. }
293+
| ClarityTypeError::InvariantViolation(_)
302294
| ClarityTypeError::InvalidPrincipalVersion(_) => {
303-
CommonCheckErrorKind::ExpectsRejectable(format!(
304-
"Unexpected error type during analysis: {err}"
305-
))
295+
CommonCheckErrorKind::Expects(format!("Unexpected error during analysis: {err}"))
306296
}
307297
ClarityTypeError::UnsupportedTypeInEpoch(ty, epoch) => {
308-
CommonCheckErrorKind::ExpectsRejectable(format!(
309-
"{ty} should not be used in {epoch}"
310-
))
298+
CommonCheckErrorKind::Expects(format!("{ty} should not be used in {epoch}"))
311299
}
312300
ClarityTypeError::UnsupportedEpoch(epoch) => {
313-
CommonCheckErrorKind::ExpectsRejectable(format!("{epoch} is not supported"))
301+
CommonCheckErrorKind::Expects(format!("{epoch} is not supported"))
314302
}
315303
}
316304
}
@@ -352,11 +340,7 @@ pub enum StaticCheckErrorKind {
352340
// Unexpected interpreter behavior
353341
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
354342
/// This error indicates a transaction would invalidate a block if included.
355-
ExpectsRejectable(String),
356-
// Unexpected interpreter behavior
357-
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
358-
/// This error does NOT indicate a transaction would invalidate a block if included.
359-
ExpectsAcceptable(String),
343+
Expects(String),
360344

361345
// Match expression errors
362346
/// Invalid syntax in an `option` match expression.
@@ -669,11 +653,7 @@ pub enum CheckErrorKind {
669653
// Unexpected interpreter behavior
670654
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
671655
/// This error indicates a transaction would invalidate a block if included.
672-
ExpectsRejectable(String),
673-
// Unexpected interpreter behavior
674-
/// Unexpected condition or failure in the type-checker, indicating a bug or invalid state.
675-
/// This error does NOT indicate a transaction would invalidate a block if included.
676-
ExpectsAcceptable(String),
656+
Expects(String),
677657

678658
// Match expression errors
679659
/// Invalid syntax in an `option` match expression.
@@ -930,7 +910,7 @@ impl CheckErrorKind {
930910
pub fn rejectable(&self) -> bool {
931911
matches!(
932912
self,
933-
CheckErrorKind::SupertypeTooLarge | CheckErrorKind::ExpectsRejectable(_)
913+
CheckErrorKind::SupertypeTooLarge | CheckErrorKind::Expects(_)
934914
)
935915
}
936916

@@ -965,19 +945,17 @@ impl CheckErrorKind {
965945
| ClarityTypeError::QualifiedContractMissingDot
966946
| ClarityTypeError::InvalidPrincipalEncoding(_)
967947
| ClarityTypeError::InvalidPrincipalLength(_)
968-
| ClarityTypeError::ResponseTypeMismatch { .. } => CheckErrorKind::ExpectsAcceptable(
969-
format!("Unexpected error type during runtime analysis: {err}"),
970-
),
971-
ClarityTypeError::InvariantViolation(_)
972-
| ClarityTypeError::InvalidPrincipalVersion(_) => CheckErrorKind::ExpectsRejectable(
973-
format!("Unexpected error type during runtime analysis: {err}"),
974-
),
948+
| ClarityTypeError::ResponseTypeMismatch { .. }
949+
| ClarityTypeError::InvariantViolation(_)
950+
| ClarityTypeError::InvalidPrincipalVersion(_) => CheckErrorKind::Expects(format!(
951+
"Unexpected error type during runtime analysis: {err}"
952+
)),
975953
ClarityTypeError::CouldNotDetermineType => CheckErrorKind::CouldNotDetermineType,
976954
ClarityTypeError::UnsupportedTypeInEpoch(ty, epoch) => {
977-
CheckErrorKind::ExpectsRejectable(format!("{ty} should not be used in {epoch}"))
955+
CheckErrorKind::Expects(format!("{ty} should not be used in {epoch}"))
978956
}
979957
ClarityTypeError::UnsupportedEpoch(epoch) => {
980-
CheckErrorKind::ExpectsRejectable(format!("{epoch} is not supported"))
958+
CheckErrorKind::Expects(format!("{epoch} is not supported"))
981959
}
982960
}
983961
}
@@ -988,7 +966,7 @@ impl StaticCheckErrorKind {
988966
pub fn rejectable(&self) -> bool {
989967
matches!(
990968
self,
991-
StaticCheckErrorKind::SupertypeTooLarge | StaticCheckErrorKind::ExpectsRejectable(_)
969+
StaticCheckErrorKind::SupertypeTooLarge | StaticCheckErrorKind::Expects(_)
992970
)
993971
}
994972

@@ -1024,26 +1002,20 @@ impl StaticCheckErrorKind {
10241002
| ClarityTypeError::TypeMismatchValue(_, _)
10251003
| ClarityTypeError::ResponseTypeMismatch { .. }
10261004
| ClarityTypeError::InvalidAsciiCharacter(_)
1027-
| ClarityTypeError::InvalidUtf8Encoding => StaticCheckErrorKind::ExpectsAcceptable(
1005+
| ClarityTypeError::InvalidUtf8Encoding
1006+
| ClarityTypeError::InvariantViolation(_)
1007+
| ClarityTypeError::InvalidPrincipalVersion(_) => StaticCheckErrorKind::Expects(
10281008
format!("Unexpected error type during static analysis: {err}"),
10291009
),
1030-
ClarityTypeError::InvariantViolation(_)
1031-
| ClarityTypeError::InvalidPrincipalVersion(_) => {
1032-
StaticCheckErrorKind::ExpectsRejectable(format!(
1033-
"Unexpected error type during static analysis: {err}"
1034-
))
1035-
}
10361010
ClarityTypeError::CouldNotDetermineSerializationType => {
10371011
StaticCheckErrorKind::CouldNotDetermineSerializationType
10381012
}
10391013
ClarityTypeError::CouldNotDetermineType => StaticCheckErrorKind::CouldNotDetermineType,
10401014
ClarityTypeError::UnsupportedTypeInEpoch(ty, epoch) => {
1041-
StaticCheckErrorKind::ExpectsRejectable(format!(
1042-
"{ty} should not be used in {epoch}"
1043-
))
1015+
StaticCheckErrorKind::Expects(format!("{ty} should not be used in {epoch}"))
10441016
}
10451017
ClarityTypeError::UnsupportedEpoch(epoch) => {
1046-
StaticCheckErrorKind::ExpectsRejectable(format!("{epoch} is not supported"))
1018+
StaticCheckErrorKind::Expects(format!("{epoch} is not supported"))
10471019
}
10481020
}
10491021
}
@@ -1158,10 +1130,10 @@ impl From<CostErrors> for StaticCheckErrorKind {
11581130
CostErrors::CostContractLoadFailure => {
11591131
StaticCheckErrorKind::CostComputationFailed("Failed to load cost contract".into())
11601132
}
1161-
CostErrors::InterpreterFailure => StaticCheckErrorKind::ExpectsRejectable(
1133+
CostErrors::InterpreterFailure => StaticCheckErrorKind::Expects(
11621134
"Unexpected interpreter failure in cost computation".into(),
11631135
),
1164-
CostErrors::Expect(s) => StaticCheckErrorKind::ExpectsRejectable(s),
1136+
CostErrors::Expect(s) => StaticCheckErrorKind::Expects(s),
11651137
CostErrors::ExecutionTimeExpired => StaticCheckErrorKind::ExecutionTimeExpired,
11661138
}
11671139
}
@@ -1177,10 +1149,10 @@ impl From<CostErrors> for CheckErrorKind {
11771149
CostErrors::CostContractLoadFailure => {
11781150
CheckErrorKind::CostComputationFailed("Failed to load cost contract".into())
11791151
}
1180-
CostErrors::InterpreterFailure => CheckErrorKind::ExpectsRejectable(
1181-
"Unexpected interpreter failure in cost computation".into(),
1182-
),
1183-
CostErrors::Expect(s) => CheckErrorKind::ExpectsRejectable(s),
1152+
CostErrors::InterpreterFailure => {
1153+
CheckErrorKind::Expects("Unexpected interpreter failure in cost computation".into())
1154+
}
1155+
CostErrors::Expect(s) => CheckErrorKind::Expects(s),
11841156
CostErrors::ExecutionTimeExpired => CheckErrorKind::ExecutionTimeExpired,
11851157
}
11861158
}
@@ -1200,10 +1172,10 @@ impl From<CostErrors> for CommonCheckErrorKind {
12001172
CostErrors::CostContractLoadFailure => {
12011173
CommonCheckErrorKind::CostComputationFailed("Failed to load cost contract".into())
12021174
}
1203-
CostErrors::InterpreterFailure => CommonCheckErrorKind::ExpectsRejectable(
1175+
CostErrors::InterpreterFailure => CommonCheckErrorKind::Expects(
12041176
"Unexpected interpreter failure in cost computation".into(),
12051177
),
1206-
CostErrors::Expect(s) => CommonCheckErrorKind::ExpectsRejectable(s),
1178+
CostErrors::Expect(s) => CommonCheckErrorKind::Expects(s),
12071179
CostErrors::ExecutionTimeExpired => CommonCheckErrorKind::ExecutionTimeExpired,
12081180
}
12091181
}
@@ -1272,8 +1244,7 @@ impl From<CommonCheckErrorKind> for CheckErrorKind {
12721244
CommonCheckErrorKind::ExpectedTraitIdentifier => {
12731245
CheckErrorKind::ExpectedTraitIdentifier
12741246
}
1275-
CommonCheckErrorKind::ExpectsRejectable(s) => CheckErrorKind::ExpectsRejectable(s),
1276-
CommonCheckErrorKind::ExpectsAcceptable(s) => CheckErrorKind::ExpectsAcceptable(s),
1247+
CommonCheckErrorKind::Expects(s) => CheckErrorKind::Expects(s),
12771248
CommonCheckErrorKind::CouldNotDetermineType => CheckErrorKind::CouldNotDetermineType,
12781249
CommonCheckErrorKind::ValueTooLarge => CheckErrorKind::ValueTooLarge,
12791250
CommonCheckErrorKind::TypeSignatureTooDeep => CheckErrorKind::TypeSignatureTooDeep,
@@ -1333,12 +1304,7 @@ impl From<CommonCheckErrorKind> for StaticCheckErrorKind {
13331304
CommonCheckErrorKind::ExpectedTraitIdentifier => {
13341305
StaticCheckErrorKind::ExpectedTraitIdentifier
13351306
}
1336-
CommonCheckErrorKind::ExpectsRejectable(s) => {
1337-
StaticCheckErrorKind::ExpectsRejectable(s)
1338-
}
1339-
CommonCheckErrorKind::ExpectsAcceptable(s) => {
1340-
StaticCheckErrorKind::ExpectsAcceptable(s)
1341-
}
1307+
CommonCheckErrorKind::Expects(s) => StaticCheckErrorKind::Expects(s),
13421308
CommonCheckErrorKind::CouldNotDetermineType => {
13431309
StaticCheckErrorKind::CouldNotDetermineType
13441310
}
@@ -1439,8 +1405,7 @@ impl DiagnosableError for StaticCheckErrorKind {
14391405
fn message(&self) -> String {
14401406
match &self {
14411407
StaticCheckErrorKind::SupertypeTooLarge => "supertype of two types is too large".into(),
1442-
StaticCheckErrorKind::ExpectsRejectable(s) => format!("unexpected interpreter behavior: {s}"),
1443-
StaticCheckErrorKind::ExpectsAcceptable(s) => s.clone(),
1408+
StaticCheckErrorKind::Expects(s) => format!("unexpected interpreter behavior: {s}"),
14441409
StaticCheckErrorKind::BadMatchOptionSyntax(source) =>
14451410
format!("match on a optional type uses the following syntax: (match input some-name if-some-expression if-none-expression). Caused by: {}",
14461411
source.message()),

clarity/src/vm/analysis/analysis_db.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ impl<'a> AnalysisDatabase<'a> {
5151
self.begin();
5252
let result = f(self).or_else(|e| {
5353
self.roll_back()
54-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")))?;
54+
.map_err(|e| StaticCheckErrorKind::Expects(format!("{e:?}")))?;
5555
Err(e)
5656
})?;
5757
self.commit()
58-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")))?;
58+
.map_err(|e| StaticCheckErrorKind::Expects(format!("{e:?}")))?;
5959
Ok(result)
6060
}
6161

@@ -66,13 +66,13 @@ impl<'a> AnalysisDatabase<'a> {
6666
pub fn commit(&mut self) -> Result<(), StaticCheckError> {
6767
self.store
6868
.commit()
69-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")).into())
69+
.map_err(|e| StaticCheckErrorKind::Expects(format!("{e:?}")).into())
7070
}
7171

7272
pub fn roll_back(&mut self) -> Result<(), StaticCheckError> {
7373
self.store
7474
.rollback()
75-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")).into())
75+
.map_err(|e| StaticCheckErrorKind::Expects(format!("{e:?}")).into())
7676
}
7777

7878
pub fn storage_key() -> &'static str {
@@ -108,8 +108,7 @@ impl<'a> AnalysisDatabase<'a> {
108108
.flatten()
109109
.map(|x| {
110110
ContractAnalysis::deserialize(&x).map_err(|_| {
111-
StaticCheckErrorKind::ExpectsRejectable("Bad data deserialized from DB".into())
112-
.into()
111+
StaticCheckErrorKind::Expects("Bad data deserialized from DB".into()).into()
113112
})
114113
})
115114
.transpose()
@@ -129,7 +128,7 @@ impl<'a> AnalysisDatabase<'a> {
129128
.flatten()
130129
.map(|x| {
131130
ContractAnalysis::deserialize(&x).map_err(|_| {
132-
StaticCheckErrorKind::ExpectsRejectable("Bad data deserialized from DB".into())
131+
StaticCheckErrorKind::Expects("Bad data deserialized from DB".into())
133132
})
134133
})
135134
.transpose()?
@@ -154,7 +153,7 @@ impl<'a> AnalysisDatabase<'a> {
154153

155154
self.store
156155
.insert_metadata(contract_identifier, key, &contract.serialize())
157-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("{e:?}")))?;
156+
.map_err(|e| StaticCheckErrorKind::Expects(format!("{e:?}")))?;
158157
Ok(())
159158
}
160159

clarity/src/vm/analysis/contract_interface_builder/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl ContractInterfaceFunction {
278278
FunctionType::Fixed(FixedFunction { returns, .. }) => {
279279
ContractInterfaceAtomType::from_type_signature(returns)
280280
}
281-
_ => return Err(StaticCheckErrorKind::ExpectsRejectable(
281+
_ => return Err(StaticCheckErrorKind::Expects(
282282
"Contract functions should only have fixed function return types!"
283283
.into(),
284284
)
@@ -290,7 +290,7 @@ impl ContractInterfaceFunction {
290290
ContractInterfaceFunctionArg::from_function_args(args)
291291
}
292292
_ => {
293-
return Err(StaticCheckErrorKind::ExpectsRejectable(
293+
return Err(StaticCheckErrorKind::Expects(
294294
"Contract functions should only have fixed function arguments!"
295295
.into(),
296296
)
@@ -402,8 +402,7 @@ impl ContractInterface {
402402

403403
pub fn serialize(&self) -> Result<String, StaticCheckError> {
404404
serde_json::to_string(self).map_err(|_| {
405-
StaticCheckErrorKind::ExpectsRejectable("Failed to serialize contract interface".into())
406-
.into()
405+
StaticCheckErrorKind::Expects("Failed to serialize contract interface".into()).into()
407406
})
408407
}
409408
}

clarity/src/vm/analysis/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub fn mem_type_check(
5757
) -> Result<(Option<TypeSignature>, ContractAnalysis), StaticCheckError> {
5858
let contract_identifier = QualifiedContractIdentifier::transient();
5959
let contract = build_ast(&contract_identifier, snippet, &mut (), version, epoch)
60-
.map_err(|e| StaticCheckErrorKind::ExpectsRejectable(format!("Failed to build AST: {e}")))?
60+
.map_err(|e| StaticCheckErrorKind::Expects(format!("Failed to build AST: {e}")))?
6161
.expressions;
6262

6363
let mut marf = MemoryBackingStore::new();
@@ -76,16 +76,14 @@ pub fn mem_type_check(
7676
Ok(x) => {
7777
// return the first type result of the type checker
7878

79-
let first_type = x
80-
.type_map
81-
.as_ref()
82-
.ok_or_else(|| {
83-
StaticCheckErrorKind::ExpectsRejectable("Should be non-empty".into())
84-
})?
85-
.get_type_expected(x.expressions.last().ok_or_else(|| {
86-
StaticCheckErrorKind::ExpectsRejectable("Should be non-empty".into())
87-
})?)
88-
.cloned();
79+
let first_type =
80+
x.type_map
81+
.as_ref()
82+
.ok_or_else(|| StaticCheckErrorKind::Expects("Should be non-empty".into()))?
83+
.get_type_expected(x.expressions.last().ok_or_else(|| {
84+
StaticCheckErrorKind::Expects("Should be non-empty".into())
85+
})?)
86+
.cloned();
8987
Ok((first_type, x))
9088
}
9189
Err(e) => Err(e.0),
@@ -154,7 +152,7 @@ pub fn run_analysis(
154152
TypeChecker2_1::run_pass(&epoch, &mut contract_analysis, db, build_type_map)
155153
}
156154
StacksEpochId::Epoch10 => {
157-
return Err(StaticCheckErrorKind::ExpectsRejectable(
155+
return Err(StaticCheckErrorKind::Expects(
158156
"Epoch 1.0 is not a valid epoch for analysis".into(),
159157
)
160158
.into())

clarity/src/vm/analysis/type_checker/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ impl FunctionType {
4848
| StacksEpochId::Epoch31
4949
| StacksEpochId::Epoch32
5050
| StacksEpochId::Epoch33 => self.check_args_2_1(accounting, args, clarity_version),
51-
StacksEpochId::Epoch10 => Err(StaticCheckErrorKind::ExpectsRejectable(
52-
"Epoch10 is not supported".into(),
53-
)
54-
.into()),
51+
StacksEpochId::Epoch10 => {
52+
Err(StaticCheckErrorKind::Expects("Epoch10 is not supported".into()).into())
53+
}
5554
}
5655
}
5756

@@ -77,10 +76,9 @@ impl FunctionType {
7776
| StacksEpochId::Epoch33 => {
7877
self.check_args_by_allowing_trait_cast_2_1(db, clarity_version, func_args)
7978
}
80-
StacksEpochId::Epoch10 => Err(StaticCheckErrorKind::ExpectsRejectable(
81-
"Epoch10 is not supported".into(),
82-
)
83-
.into()),
79+
StacksEpochId::Epoch10 => {
80+
Err(StaticCheckErrorKind::Expects("Epoch10 is not supported".into()).into())
81+
}
8482
}
8583
}
8684
}

0 commit comments

Comments
 (0)