Skip to content

Commit 648ace3

Browse files
bkioshnMr-Leshiy
andauthored
chore(signed-doc): add problem report to doc ref (#378)
Signed-off-by: bkioshn <bkioshn@gmail.com> Co-authored-by: Alex Pozhylenkov <leshiy12345678@gmail.com>
1 parent 7f2d501 commit 648ace3

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

rust/signed_doc/src/validator/rules/param_link_ref.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,21 @@ impl ParameterLinkRefRule {
3131
&self, doc: &CatalystSignedDocument, provider: &Provider,
3232
) -> anyhow::Result<bool>
3333
where Provider: CatalystSignedDocumentProvider {
34+
let context: &str = "Parameter link ref rule check";
3435
if let Self::Specified { field } = self {
3536
let param_link_ref_validator = |ref_doc: CatalystSignedDocument| {
36-
// The parameters MUST be the same
37-
doc.doc_meta().parameters() == ref_doc.doc_meta().parameters()
37+
// The parameters MUST be the same, if not record the error
38+
if doc.doc_meta().parameters() != ref_doc.doc_meta().parameters() {
39+
doc.report().invalid_value(
40+
"parameters",
41+
&format!("Reference doc param: {:?}", ref_doc.doc_meta().parameters()),
42+
&format!("Doc param: {:?}", doc.doc_meta().parameters()),
43+
&format!("{context}, parameters must be the same"),
44+
);
45+
return false;
46+
}
47+
true
3848
};
39-
4049
// Which field is use for linked reference
4150
let param_link_ref = match field {
4251
LinkField::Ref => doc.doc_meta().doc_ref(),
@@ -45,7 +54,7 @@ impl ParameterLinkRefRule {
4554

4655
let Some(param_link_ref) = param_link_ref else {
4756
doc.report()
48-
.missing_field("Link ref", "Invalid link reference");
57+
.missing_field("Link ref", &format!("{context}: Invalid link reference"));
4958
return Ok(false);
5059
};
5160

rust/signed_doc/src/validator/rules/reply.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ impl ReplyRule {
5252
};
5353

5454
// Checking the ref field of ref doc, it should match the ref field of the doc
55-
ref_doc_dr == doc_dr
55+
// If not record the error
56+
if ref_doc_dr != doc_dr {
57+
doc.report().invalid_value(
58+
"ref",
59+
&format!("Reference doc ref: {ref_doc_dr}"),
60+
&format!("Doc ref: {doc_dr}"),
61+
&format!("{context}, ref must be the same"),
62+
);
63+
return false;
64+
}
65+
true
5666
};
5767
return validate_doc_refs(reply_ref, provider, doc.report(), reply_validator).await;
5868
} else if !optional {

0 commit comments

Comments
 (0)