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

Why is TaskCanceledException not being caught but other exceptions are? #70

Open
dansorescu-mhc opened this issue Jul 12, 2023 · 1 comment

Comments

@dansorescu-mhc
Copy link

I am using Prise Plugin Framework and MailKit SMTP Client.

During the ConnectAsync call, if the async call timeouts, it will throw a TaskCanceledException. This will be caught in the caller and after logging it will be thrown down the call stack. But this will not be caught after the Execute method in the Prise plugin and the app will crash - other exceptions are being caught fine and don't crash the app.

try
{
    await _smtpClient.ConnectAsync(sendEmail.Host, sendEmail.Port);
    // other code
}
catch
{
    // logging
    throw;
}

This code is being called by the plugin with return await service.ExecuteAsync(parameters, context);

I'm expecting this to throw the exception to its parent but it doesn't happen.

The plugin looks as follows:

[Plugin(PluginType = typeof(IPlugin))]
public class Email : BasePlugin<EmailInputModel>
{
	[field: PluginService(ProvidedBy = ProvidedBy.Host, ServiceType = typeof(IServiceProvider))]
	private IServiceProvider ServiceProvider { get; set; }

	[PluginActivated]
	public void OnActivated()
	{
		InitializeServices(ServiceProvider);
	}

	protected override async Task<PluginExecutionResult> ExecutePluginAsync(
		InputModel parameters,
		PluginExecutionContext context,
		IServiceProvider provider)
	{
		IEmailPluginService service = provider.GetRequiredService<IEmailPluginService>();
		return await service.ExecuteAsync(parameters, context);
	}
}
@dansorescu-mhc
Copy link
Author

We can close this issue since I managed to fix it by catching the OperationCanceledException and throw a custom exception in the catch block

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

No branches or pull requests

1 participant