Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: test error semantics #112

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Conversation

ARR4N
Copy link
Collaborator

@ARR4N ARR4N commented Feb 3, 2025

Why this should be merged

Testing errors by matching their strings results in change-detector tests that can result in false positives due to nothing more than changing the message intended for humans. Changing an implementation and a test at the same time adds uncertainty to the correctness of the change, but change-detector tests force this to be done.

See also: Test error semantics

How this works

The errs package is introduced to allow tagging of errors with distinct identifiers that are intended to be immutable (i.e. no change-detector tests) even when messages change. The IDs can only be extracted via the errs package, which is in internal to stop leakage of the errors via the API such that users can depend on them as per Hyrum's Law:

With a sufficient number of users of an API,
it does not matter what you promise in the contract:
all observable behaviors of your system
will be depended on by somebody.

How this was tested

Unit test for ID extraction + usage in params tests.

@ARR4N ARR4N marked this pull request as ready for review February 4, 2025 10:41
@ARR4N ARR4N requested review from a team, darioush, qdm12 and ceyonur and removed request for a team February 4, 2025 10:41
@ARR4N ARR4N marked this pull request as draft February 4, 2025 14:18
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.

1 participant