Skip to content

prefeature(library/Attempt): lets NonActionableError conform to "constructable" #540

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

Conversation

bjacobgordon
Copy link
Collaborator

@bjacobgordon bjacobgordon commented Jul 17, 2025

  • while NonActionableError.throw is the recommended way of constructing and propagating an instance, there's no inherent danger in directly constructing
  • unblocks fix(library/math): guards against infinite operands in greatestCommonDivisor #538
    • a common way to detect constructors is to check for conformance to an interface like:
      interface DirectlyConstructable {
        new: (...parameters: any[]): any;
      }
      • useful in scenarios where constructors are passed to implementations that "reconstruct" an instance
    • any class that implements DirectlyConstructable will inherently conform to:
      interface InstanceMatchable {
        [Symbol.hasInstance]: (...parameters: any[]): boolean;
      }
      • objects that conform to this interface are guaranteed to be compatible with the instanceOf operator
    • a problem arises when a class regulates constructor usage via static factories
      • on the one hand, it's no longer "directly constructable"
      • but on the other, the class can still "have instances"
      • so, if the goal is to use instanceOf and not necessarily "reconstruct" an instance, then conformance to DirectlyConstructable is needlessly restrictive.

@bjacobgordon bjacobgordon changed the title prefeature(library/Attempt): exposes constructor of NonActionableError prefeature(library/Attempt): lets NonActionableError be considered "constructable" Jul 17, 2025
@bjacobgordon bjacobgordon changed the title prefeature(library/Attempt): lets NonActionableError be considered "constructable" prefeature(library/Attempt): lets NonActionableError conform to "constructable" Jul 17, 2025
@bjacobgordon bjacobgordon merged commit 3eea16a into nod-ai:integration Jul 17, 2025
7 checks passed
@bjacobgordon bjacobgordon deleted the prefeature(library/Attempt)--exposes-constructor-of-`NonActionableError` branch July 17, 2025 14:57
@bjacobgordon bjacobgordon self-assigned this Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant