src/Curiosity.Migrations.PostgreSQL/PostgreDbProvider.cs
/// <summary>
/// Try to execute passed function catching common postgres exceptions.
/// All catched exceptions will be processed and re-thrown.
/// </summary>
/// <param name="action">Code that should be executed and that can cause postgres exceptions.</param>
/// <param name="errorType">Type for exception that will be thrown if unknown exception occurres.</param>
/// <param name="errorMessage">Message for exception that will be thrown if unknown exception occurres.</param>
/// <exception cref="InvalidOperationException">In case when IOE get cought - it will be rethrown.</exception>
/// <exception cref="MigrationException">Any exception except IOE will be rethrown as MigrationException.</exception>
Try to execute passed function catching common postgres exceptions.
All catched exceptions will be processed and re-thrown.
Try to execute passed function catching common postgres exceptions . All catched exceptions will be processed and re - thrown .
private async Task TryExecute(Func<Task> action, MigrationError errorType, string errorMessage)
        {
            try
            {
                await action.Invoke();
            }
            catch (PostgresException e)
                when (e.SqlState.StartsWith("08")
                      || e.SqlState == "3D000"
                      || e.SqlState == "3F000")
            {
                throw new MigrationException(MigrationError.ConnectionError, $"Can not connect to DB {DbName}", e);
            }
            catch (PostgresException e)
                when (e.SqlState.StartsWith("28")
                      || e.SqlState == "0P000"
                      || e.SqlState == "42501"
                      || e.SqlState == "42000")
            {
                throw new MigrationException(MigrationError.AuthorizationError,
                    $"Invalid authorization specification for {DbName}", e);
            }
            catch (NpgsqlException e)
            {
                throw new MigrationException(MigrationError.ConnectionError, $"Can not connect to DB {DbName}", e);
            }
            catch (InvalidOperationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new MigrationException(errorType, errorMessage, e);
            }
        }
private async Task TryExecute ( Func < Task > action , MigrationError errorType , string errorMessage ) { try { await action . Invoke ( ) ; } catch ( PostgresException e ) when ( e . SqlState . StartsWith ( " " ) || e . SqlState == " " || e . SqlState == " " ) { throw new MigrationException ( MigrationError . ConnectionError , $" Can not connect to DB  { DbName } " , e ) ; } catch ( PostgresException e ) when ( e . SqlState . StartsWith ( " " ) || e . SqlState == " " || e . SqlState == " " || e . SqlState == " " ) { throw new MigrationException ( MigrationError . AuthorizationError , $" Invalid authorization specification for  { DbName } " , e ) ; } catch ( NpgsqlException e ) { throw new MigrationException ( MigrationError . ConnectionError , $" Can not connect to DB  { DbName } " , e ) ; } catch ( InvalidOperationException ) { throw ; } catch ( Exception e ) { throw new MigrationException ( errorType , errorMessage , e ) ; } }
Try to execute passed function catching common postgres exceptions.
Try to execute passed function catching common postgres exceptions .
In case when IOE get cought - it will be rethrown.
In case when IOE get cought - it will be rethrown .
Any exception except IOE will be rethrown as MigrationException.
Any exception except IOE will be rethrown as MigrationException .
action
Func<Task>
Code that should be executed and that can cause postgres exceptions.
Code that should be executed and that can cause postgres exceptions .
errorType
MigrationError
Type for exception that will be thrown if unknown exception occurres.
Type for exception that will be thrown if unknown exception occurres .
errorMessage
string
Message for exception that will be thrown if unknown exception occurres.
Message for exception that will be thrown if unknown exception occurres .