Skip to content

Commit

Permalink
Improving error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronjeline committed Oct 12, 2023
1 parent 85dfca8 commit 39495e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cedar-policy-core/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ mod json_parsing_tests {
EntityJsonParser::new(None, Extensions::all_available(), TCComputation::ComputeNow);
let error = eparser.from_json_value(json).err().unwrap().to_string();
assert!(
error.contains("in uid field of <unknown entity>, expected a literal entity reference"),
error.contains("in uid field of <unknown entity>, invalid escape. The `__expr` escape is no longer supported"),
"{}",
error
);
Expand Down Expand Up @@ -1080,7 +1080,7 @@ mod json_parsing_tests {
EntityJsonParser::new(None, Extensions::all_available(), TCComputation::ComputeNow);
let error = eparser.from_json_value(json).err().unwrap().to_string();
assert!(
error.contains("`__expr` tag is no longer supported"),
error.contains("`__expr` escape is no longer supported"),
"Actual error message was: {}",
error
);
Expand All @@ -1102,7 +1102,7 @@ mod json_parsing_tests {
"a b c": { "__extn": { "fn": "ip", "arg": "222.222.222.0/24" } }
},
"parents": [
{ "__expr": { "type" : "test_entity_type", "id" : "bob"} },
{ "__expr": "test_entity_type::\"Alice\"" },
{ "__entity": { "type": "test_entity_type", "id": "catherine" } }
]
}
Expand All @@ -1111,7 +1111,7 @@ mod json_parsing_tests {
EntityJsonParser::new(None, Extensions::all_available(), TCComputation::ComputeNow);
let error = eparser.from_json_value(json).err().unwrap().to_string();
assert!(
error.contains(r#"in parents field of `test_entity_type::"Alice"`, expected a literal entity reference"#),
error.contains(r#"in parents field of `test_entity_type::"Alice"`, invalid escape. The `__expr` escape is no longer supported"#),
"Actual error message was: {}",
error
);
Expand Down
9 changes: 9 additions & 0 deletions cedar-policy-core/src/entities/json/jsonvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,12 @@ impl<'e> ValueParser<'e> {
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(untagged)]
pub enum EntityUidJSON {
/// Explicit `__expr` syntax.
/// This is no longer supported deprecated and is only here for generating nice error messages.
ExplicitExprEscape {
/// Contents are ignored.
__expr: String,
},
/// Explicit `__entity` escape; see notes on JSONValue::EntityEscape
ExplicitEntityEscape {
/// JSON object containing the entity type and ID
Expand Down Expand Up @@ -578,6 +584,9 @@ impl EntityUidJSON {
ctx: Box::new(ctx()),
got: Box::new(Either::Left(v)),
}),
Self::ExplicitExprEscape { __expr } => {
Err(JsonDeserializationError::ExprTag(Box::new(ctx())))
}
}
}
}
Expand Down

0 comments on commit 39495e9

Please sign in to comment.