Skip to content

Commit e48dd9a

Browse files
Remove ParseErrors::errors_as_strings (fix #543) (#882)
Signed-off-by: John Kastner <[email protected]>
1 parent 7cb7e32 commit e48dd9a

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

cedar-policy-core/src/parser/err.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,6 @@ impl ParseErrors {
705705
pub(super) fn push(&mut self, err: impl Into<ParseError>) {
706706
self.0.push(err.into());
707707
}
708-
709-
/// returns a Vec with stringified versions of the ParseErrors
710-
pub fn errors_as_strings(&self) -> Vec<String> {
711-
self.0.iter().map(ToString::to_string).collect()
712-
}
713708
}
714709

715710
impl Display for ParseErrors {

cedar-policy/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131
in an internal crate, allowing us to make semver incompatible changes. (#857)
3232
- Removed the (deprecated) `frontend` module in favor of the new `ffi` module
3333
introduced in 3.2.0. See #757.
34+
- Removed `ParseErrors::errors_as_strings`. Callers should consider examining
35+
the rich data provided by `miette::Diagnostic`, for instance `.help()` and
36+
`labels()`. Callers can continue using the same behavior by calling
37+
`.iter().map(ToString::to_string)`. (#882, resolving #543)
3438

3539
## [3.2.0] - Coming Soon
3640

cedar-testing/tests/cedar-policy-cli/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ fn perform_integration_test_from_json(jsonfile: impl AsRef<Path>) {
100100
);
101101
assert!(
102102
parse_errs
103-
.errors_as_strings()
104103
.iter()
105-
.any(|s| s.ends_with("not a function")),
104+
.any(|e| e.to_string().ends_with("not a function")),
106105
"unexpected parse errors in test {}: {}",
107106
jsonfile.display(),
108107
parse_errs,

cedar-wasm/src/policies_and_templates.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn policy_text_to_json(cedar_str: &str) -> PolicyToJsonResult {
7676
match parse_policy_or_template_to_est(cedar_str) {
7777
Ok(policy) => PolicyToJsonResult::Success { policy },
7878
Err(err) => PolicyToJsonResult::Error {
79-
errors: err.errors_as_strings(),
79+
errors: err.iter().map(ToString::to_string).collect(),
8080
},
8181
}
8282
}
@@ -97,7 +97,7 @@ pub enum CheckParsePolicySetResult {
9797
pub fn check_parse_policy_set(input_policies_str: &str) -> CheckParsePolicySetResult {
9898
match PolicySet::from_str(input_policies_str) {
9999
Err(parse_errors) => CheckParsePolicySetResult::Error {
100-
errors: parse_errors.errors_as_strings(),
100+
errors: parse_errors.iter().map(ToString::to_string).collect(),
101101
},
102102
Ok(policy_set) => {
103103
let policies_count: Result<i32, <i32 as TryFrom<usize>>::Error> =
@@ -132,7 +132,7 @@ pub enum CheckParseTemplateResult {
132132
pub fn check_parse_template(template_str: &str) -> CheckParseTemplateResult {
133133
match Template::from_str(template_str) {
134134
Err(parse_errs) => CheckParseTemplateResult::Error {
135-
errors: parse_errs.errors_as_strings(),
135+
errors: parse_errs.iter().map(ToString::to_string).collect(),
136136
},
137137
Ok(template) => match template.slots().count() {
138138
1 | 2 => CheckParseTemplateResult::Success {

0 commit comments

Comments
 (0)