Election-Tech-Initiative / electionguard-cpp

A C++ implementation of ElectionGuard specification focused on encryption components.
https://www.electionguard.vote/
MIT License
23 stars 26 forks source link

♻️ Refactor C# console logs with a custom exception #211

Closed AddressXception closed 2 years ago

AddressXception commented 3 years ago

Is there an existing issue for this?

Suggestion

There is a wrapping C# project around the C under bindings/netstandard/ElectionGuard. The methods that communicate across the C interface should throw exceptions if the return status code indicates a failure.

These lines are a good example.
https://github.com/microsoft/electionguard-cpp/blob/99788bc9fb76ee2293e9b131965b91b85ba6fee3/bindings/netstandard/ElectionGuard/ElectionGuard.Encryption/NativeInterface.cs#L357-L362

Possible Implementation

The ideal case would be to create a custom Exception that could take the message that is currently logged. This way a logger can easily be made to catch the exceptions and log them.

ElectionGuardException should be a suitable name for now. The status can then be passed in as a parameter.

if (status != Status.ELECTIONGUARD_STATUS_SUCCESS)
{
    throw ElectionGuardException("DisjunctiveChaumPedersenProof Error Free", status);
}
return true;

Anything else?

ElectionGuard.Encryption Project: https://github.com/microsoft/electionguard-cpp/tree/main/bindings/netstandard/ElectionGuard/ElectionGuard.Encryption

SteveMaier-IRT commented 2 years ago

This has been merged into #184