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

Allow stack track logging on failing Result.Act() #64

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

Conversation

Corniel
Copy link
Contributor

@Corniel Corniel commented Mar 31, 2023

From multiple channels, people have given the feedback that debugging longer chains of .Act() can be hard to debug. This PR is an attempt to improve the debugger experience.

The main idea is to add a custom IValidationMessage that contains the StackTrace once a .Act() execution results in an invalid result.

Corniel Nobel added 2 commits March 31, 2023 15:12
@Corniel Corniel marked this pull request as ready for review March 31, 2023 13:22
@Corniel Corniel self-assigned this Mar 31, 2023
@Corniel Corniel requested review from Sjaaky and pmdevers March 31, 2023 18:03
@@ -85,7 +85,7 @@ public Result<TOut> Act<TOut>(Func<TModel, Result<TOut>> action)
return new(outcome.IsValid
? outcome.Value
: default,
((FixedMessages)Messages).AddRange(outcome.Messages));
((FixedMessages)Messages).AddRange(outcome.Messages).Add(ActFailed.New(outcome.IsValid)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding a new message might not be visible enough, especially if you have many other error messages. I would prefer to see something more in line with debugger breakpoints.

/// <inheritdoc />
public ValidationSeverity Severity
=> Trace is { }
? ValidationSeverity.Error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would perhaps be beneficial to introduce a new severity for this (e.g. Debug)

Copy link
Contributor Author

@Corniel Corniel Apr 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given:

/// <summary>The validation severity of a <see cref="IValidationMessage"/>.</summary>
public enum ValidationSeverity
{
   /// <summary>Successful message (so no severity).</summary>
   None = -1,

   /// <summary>Informative message severity.</summary>
   Info = 0,

   /// <summary>Warning message severity.</summary>
   Warning = 1,

   /// <summary>Error message severity.</summary>
   Error = 2,
}

That can be challenging. I already considered Info a better severity, but a new level might be problematic.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how this snippet is meant to show that adding a new severity is challenging? If you mean that the integer values of the enum are meant to also bear some meaning, then I would propose to make Debug have the value of -2, since the message is theoretically only present during debugging and is therefore similar to None (except that it doesn't get filtered).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-2 would indeed be the logical value. But there is at least 1 place that has logic stating: Severity > Severity.None. In this case to add messages to a result to create. Furthermore, by making the value public, also other messages with a DEBUG severity can be created, I don't think I like that to happen.

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.

None yet

3 participants