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

This causes task cancelled unhandled exception #283

Open
ALSULTAN opened this issue Sep 27, 2024 · 4 comments
Open

This causes task cancelled unhandled exception #283

ALSULTAN opened this issue Sep 27, 2024 · 4 comments

Comments

@ALSULTAN
Copy link

@ALSULTAN
Copy link
Author

System.AggregateException: TaskExceptionHolder_UnhandledException (Operation canceled)
 ---> System.Net.Sockets.SocketException (89): Operation canceled
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 )
   at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
   at System.Net.Sockets.TcpClient.CompleteConnectAsync(Task )
   Exception_EndOfInnerExceptionStack

@igorocampos
Copy link
Collaborator

igorocampos commented Sep 27, 2024

Not sure what you meant, but the code you linked is inside a try catch

catch (Exception e)
{
    Logging.Logger?.LogError(e, "[{Function}]:[{PrinterName}] Unable to connect to printer.", $"{this}.{MethodBase.GetCurrentMethod().Name}", _settings.PrinterName);
    client.Close();
    throw;
}

You can check the logs for the error details, but sounds like you are unable to connect to your printer...

@ALSULTAN
Copy link
Author

Actually, there is a throw on catch statement
and the method RunTask is throwing another ThrowIfCancellationRequested
hope this helps. anyone who knows the code well can see the exception is propagating to the caller application

@igorocampos
Copy link
Collaborator

igorocampos commented Sep 28, 2024

Yep, the throw is on purpose, so the exception is not swallowed by the library, and the lib user can act upon it, and actually know there was a connection error, otherwise it would just silently fail for you when such a lack of connection happens.

If you have a better proposal of how to handle that, you are welcome to open a PR as this is an open source project :)

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

2 participants