Skip to content

Commit

Permalink
Provide a better exception message for invalid data source config. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kavatari authored Jun 23, 2023
1 parent 5784b52 commit f3e21dc
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/EFCore.PG/Infrastructure/Internal/NpgsqlOptionsExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Globalization;
using System.Net.Security;
using System.Text;
using Npgsql.EntityFrameworkCore.PostgreSQL.Internal;

namespace Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;

Expand Down Expand Up @@ -242,12 +243,25 @@ public override void Validate(IDbContextOptions options)
var dataSource = DataSource
?? options.FindExtension<CoreOptionsExtension>()?.ApplicationServiceProvider?.GetService<NpgsqlDataSource>();

if (dataSource is not null
&& (ProvideClientCertificatesCallback is not null
|| RemoteCertificateValidationCallback is not null
|| ProvidePasswordCallback is not null))
if (dataSource is not null)
{
throw new InvalidOperationException();
if (ProvideClientCertificatesCallback is not null)
{
throw new InvalidOperationException(
"When passing an NpgsqlDataSource to UseNpgsql(), call 'ProvideClientCertificatesCallback' on NpgsqlDataSourceBuilder rather than in UseNpgsql().");
}

if (RemoteCertificateValidationCallback is not null)
{
throw new InvalidOperationException(
"When passing an NpgsqlDataSource to UseNpgsql(), call 'RemoteCertificateValidationCallback' on NpgsqlDataSourceBuilder rather than in UseNpgsql().");
}

if (ProvidePasswordCallback is not null)
{
throw new InvalidOperationException(
"When passing an NpgsqlDataSource to UseNpgsql(), 'ProviderPasswordCallback' cannot be used in UseNpgsql(). See https://www.npgsql.org/doc/security.html for configuring passwords and token rotation on NpgsqlDataSourceBuilder.");
}
}

if (UseRedshift && _postgresVersion is not null)
Expand Down

0 comments on commit f3e21dc

Please sign in to comment.