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

Use Func to pass custom exception to Guard methods #350

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

canro91
Copy link
Contributor

@canro91 canro91 commented Jul 1, 2024

It changes the optional exception to a factory using Func.

From

Guard.Against.Empty(anEmptyString, exception: new SomethingWrongHappenedException());

To

Guard.Against.Empty(anEmptyString, exceptionCreator: () => SomethingWrongHappenedException());

It follows the same approach from 6186c68 in all other methods.

Relates to: #344

@ardalis ardalis merged commit 08d3340 into ardalis:main Jul 1, 2024
1 check failed
@canro91 canro91 deleted the pass-custom-exception-as-factory branch July 2, 2024 19:56
@manolitooo
Copy link

Just adding a note. This should have been into a v5.0.0 of the library, since it is a breaking change. The signature of all methods have changed, therefore depending packages which used v4.5.0 cannot find the old signature in the v4.6.0.

The scenario where I found out this runtime exception is the following:

  • I have a custom package "A" where I use Ardalis.GuardClauses at v4.5.0.
  • I have an application where I use the custom package "A" and also Ardalis.GuardClauses at v4.5.0.
  • Upgraded to Ardalis.GuardClauses v4.6.0 in the application.

The application starts failing then when calling the package "A" because it cannot find the old method's signature in the current assembly.

I have downgraded to v4.5.0 until the custom package "A" is also upgraded.

@ardalis
Copy link
Owner

ardalis commented Jul 30, 2024

Shoot, you're absolutely right. My error. I had meant to make the change to the signature in between releases, meaning that the short-lived version where the exception was added to the method signatures would never have been published. Thus, fixing that so that it took in an (optional) Func would have been an additive-only change and thus a minor release.

Probably my best option at this point is to publish a v5 version just so (hopefully) folks jump to that from 4.x instead of to the mistakenly versioned 4.6 release.

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.

3 participants