Try icon indicating copy to clipboard operation
Try copied to clipboard

Flowing context

Open i3arnon opened this issue 6 years ago • 3 comments

Currently a faulted instance doesn't carry any context (other than the exception). It can be somewhat limiting. The only thing you can really do with one is log the exception itself, but multiple Try instances you don't know the origin of it.

I'm not sure what's the appropriate solution here, but do you see this as an issue that needs a solution?

I can imagine adding a Try<TInput, TResult> (which can also avoid capturing):

var block =
    new TransformBlock<string, Try<string, string>>(
        uri => Try.Create(uri, innerUri => client.GetStringAsync(innerUri)));

I can make that a PR if you're interested. WDYT?

i3arnon avatar Jun 18 '19 16:06 i3arnon

This should be solvable by using ExceptionDispatchInfo, I believe.

DaZombieKiller avatar Oct 11 '19 09:10 DaZombieKiller

Sorry for the silence! For some reason GH never notified me of this issue, so I just saw it...

You bring up a good point, and one which makes sense. I've had similar wants when using dataflow (even without Try), so I wonder if a separate solution would be better. Have to think about this for a bit.

StephenCleary avatar Oct 03 '20 12:10 StephenCleary

As a workaround, can Exception.Data be used?

var block1 = new TransformBlock<Try<int>, Try<string>>(msg =>
{
	return msg.Map(value => 
	{
		try
		{
			if (value > 2)
			{
				throw new Exception("blech");
			}

			return value.ToString();
		}
		catch (Exception ex)
		{
			ex.Data["block1.state"] = value;
			throw;
		}		
	});
});

reponemec avatar Dec 26 '20 15:12 reponemec