Skip to content

suggestion: don't use std/assert in implementation code #4865

Closed
@iuioiua

Description

Using assertions from std/assert within implementation code in the codebase has a few drawbacks:

  1. In cases where the user needs to error handle an API that uses assertions from std/assert, they need to import and use AssertionError.
  2. While error messages provide the majority of the context behind an error, the constructor name does, too. I.e. RangeError. AssertionError is generic and doesn't add any context to the error.
  3. It introduces an added dependency. In most cases, this doesn't matter. But for some, it does.

For these reasons, I suggest that we remove the use of assertions from std/assert within the implementation code in the Standard Library and instead use native error classes where possible. In cases where these native error classes do not fit, we can create and export custom error classes that extend Error. Doing so requires minimal code changes and can be more explicit than calling a generic assertion.

Metadata

Assignees

No one assigned

    Labels

    suggestiona suggestion yet to be agreed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions