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

Exception handled via LogInformation instead of LogError #18

Open
1 task done
sunnamed434 opened this issue Jul 28, 2024 · 2 comments
Open
1 task done

Exception handled via LogInformation instead of LogError #18

sunnamed434 opened this issue Jul 28, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@sunnamed434
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Library Version

6.0.1-beta.41

What happened?

The problem can be seen here, is LogInformation intended instead of using LogError(exception, ..) ? I guess it was not updated because dbup-mysql moved to Microsoft logging style, in my case it's problematic because: I can't handle this exception, I have to create own implementation of logger and check if format argument is a Database not found on server with connection string in settings, instead I want to fail my app by handling this exception (for example re-throwing the exception) and outputting more information about what happened.

Relevant log output

2024-07-28 21:15:02 Database not found on server with connection string in settings: Unable to connect to any of the specified MySQL hosts.
2024-07-28 21:15:02 Unhandled exception. MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
2024-07-28 21:15:02  ---> System.Net.Sockets.SocketException (111): Connection refused
2024-07-28 21:15:02    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
2024-07-28 21:15:02    at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
2024-07-28 21:15:02    at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
2024-07-28 21:15:02 --- End of stack trace from previous location ---
2024-07-28 21:15:02    at System.Net.Sockets.TcpClient.CompleteConnectAsync(Task task)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.NativeDriver.<>c.<OpenAsync>b__38_0(Exception ex)
2024-07-28 21:15:02    at System.AggregateException.Handle(Func`2 predicate)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.NativeDriver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.Driver.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.Driver.CreateAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.Driver.CreateAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnectionAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnectionAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.MySqlPool.TryToGetDriverAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.MySqlPool.GetConnectionAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
2024-07-28 21:15:02    at MySql.Data.MySqlClient.MySqlConnection.Open()
2024-07-28 21:15:02    at MySqlExtensions.MySqlDatabase(SupportedDatabasesForEnsureDatabase supported, String connectionString, IUpgradeLog logger, Int32 timeout, String collation) in /_/src/dbup-mysql/MySqlExtensions.cs:line 172
2024-07-28 21:15:02    at MySqlExtensions.MySqlDatabase(SupportedDatabasesForEnsureDatabase supported, String connectionString) in /_/src/dbup-mysql/MySqlExtensions.cs:line 98
2024-07-28 21:15:02    at UnturnedGuardAPI.App.Configurations.DependencyInjection.PrepareDatabases(IConfiguration configuration) in /src/src/UnturnedGuardAPI.App/Configurations/DependencyInjection.cs:line 28
2024-07-28 21:15:02    at Program.<Main>$(String[] args) in /src/src/UnturnedGuardAPI.App/Program.cs:line 5
2024-07-28 21:15:02    at Program.<Main>(String[] args)
@sunnamed434 sunnamed434 added the bug Something isn't working label Jul 28, 2024
@droyad
Copy link
Member

droyad commented Jul 29, 2024

I splunked a bit and it has been this way since the original PR.

I think we should throw an exception here. I'm not that familiar with MySQL.

Is there any case we get to that point and everything is ok except for the database not existing? The DatabaseExists code looks like it should work without exception. When does it throw an exception?

@sunnamed434
Copy link
Author

I think we should throw an exception here. I'm not that familiar with MySQL.

Yep, I do agree about that. 👍

Is there any case we get to that point and everything is ok except for the database not existing? The DatabaseExists code looks like it should work without exception. When does it throw an exception?

It throws an exception if it can't connect to the database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants