Skip to content

Commit

Permalink
Check SqlState instead of error message
Browse files Browse the repository at this point in the history
Instead of checking for the exception message containing "does not exist", check if SqlState matches PostgresErrorCodes.UndefinedTable ("42P01").
  • Loading branch information
Tobias Grimm committed Dec 30, 2024
1 parent d1ef0d6 commit 876d853
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Weasel.Postgresql.Tests/IntegrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected async Task CreateSchemaObjectInDatabase(ISchemaObject schemaObject)
catch (NpgsqlException e)
{
// Quirk of postgres metadata tables, this will throw on the partition querying if the table does not already exist
if (!e.Message.Contains("does not exist"))
if (e.SqlState != PostgresErrorCodes.UndefinedTable)
{
throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public async Task InitializeAsync(NpgsqlConnection conn, CancellationToken token
// 42P01: relation "public.mt_tenant_partitions" does not exist
catch (NpgsqlException e)
{
if (e.Message.Contains("does not exist"))
if (e.SqlState == PostgresErrorCodes.UndefinedTable)
{
_hasInitialized = true;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Weasel.Postgresql/Tables/Table.FetchExisting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ from pg_class base_tb
}
catch (NpgsqlException e)
{
if (!e.Message.Contains("does not exist")) throw;
if (e.SqlState != PostgresErrorCodes.UndefinedTable) throw;
}
return result;
}
Expand Down

0 comments on commit 876d853

Please sign in to comment.