refactor(sns): Use ic-nervous-system-agent in sns-audit #1756
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
sns-audit is available as a library, which makes it tempting to use in tests and in the CLI. However, there are some blockers:
Additionally, the errors from sns-audit errors are all strings. This is not optimal for consuming it as a library where you might want to have some logic that depends on the particular error that occurred, if one didi.
Solution
Rewrite sns-audit to use ic-nervous-system-agent, and use an explicit error type rather than using strings.
Notes
The error messages have changed slightly. They no longer mention the SNS's name. It is now mentioned sooner.
New:
Old:
This was done to make the error type simpler. Otherwise, it would have to carry the SNS name information in all cases where it was relevant. Since it is still printed slightly higher up, and hopefully people know the SNSes they are auditing anyway, I hope that's just as good.
How to review this PR
The first commit makes changes to ic-nervous-system-agent to add helpers that will be useful to sns-audit.
The second commit changes sns-audit to use ic-nervous-system-agent. There, you can see that the implementation of sns-audit is dramatically simplified – it now is not concerned with the details of how to call the canisters, as that is handled by ic-nervous-system-agent.