Skip to content

lang: add support for logging expected and actual values and pubkeys - #1572

Merged
paul-schaaf merged 21 commits into
otter-sec:masterfrom
paul-schaaf:lang/dynamic-errors
Mar 15, 2022
Merged

lang: add support for logging expected and actual values and pubkeys#1572
paul-schaaf merged 21 commits into
otter-sec:masterfrom
paul-schaaf:lang/dynamic-errors

Conversation

@paul-schaaf

@paul-schaaf paul-schaaf commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

closes #1586

closes #1464

Future PRs should add more require statements that abstract away the implementation details

macros added in this PR:

  • require_eq macro that is meant to be used with non-pubkey values and results in the following output:
'Program log: AnchorError thrown in programs/errors/src/lib.rs:68. Error Code: ValueMismatch. Error Number: 6126. Error Message: ValueMismatch.',
'Program log: Left: 5241',
'Program log: Right: 124124124'
  • require_keys_eq macro that is meant to be used with pubkey values and results in the following output:
'Program log: AnchorError thrown in programs/errors/src/lib.rs:73. Error Code: ValueMismatch. Error Number: 6126. Error Message: ValueMismatch.',
'Program log: Left:',
'Program log: HCGsxsDZEKWnaS5t7JBct6cyyLS6Jcx7Mmn4KjUQokZY',
'Program log: Right:',
'Program log: Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS'

These macros can be used like this require_eq(value1, value2) in which case they return an error defined by us or with a custom error require_eq(value1,value2,MyError:SomeError). The require macro has also been changed to work the same way

Log statement are intentionally Left and Right and not Expected and Actual because future require macros would not fit those descriptions (e.g. require_gt)

@paul-schaaf
paul-schaaf marked this pull request as ready for review March 8, 2022 19:50
@paul-schaaf
paul-schaaf marked this pull request as draft March 8, 2022 19:55
@paul-schaaf
paul-schaaf marked this pull request as ready for review March 8, 2022 20:24
@armaniferrante

Copy link
Copy Markdown
Contributor

merge conflicts

@paul-schaaf
paul-schaaf merged commit 721fe66 into otter-sec:master Mar 15, 2022
@jamie-osec jamie-osec added this to the Pre-1.0 milestone Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lang: provide ways to log expected vs actual values when an error occurs lang: Program id errors should log the program addresses

3 participants