Skip to content

Commit

Permalink
Improve error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Mezach <[email protected]>
  • Loading branch information
jmezach committed Oct 11, 2024
1 parent 9f27f26 commit 52bb7fb
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/MSBuild.Sdk.SqlProj.Aspire/SqlProjectPublishService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@ public async Task PublishSqlProject(SqlProjectResource sqlProject, SqlServerData
{
var logger = _resourceLoggerService.GetLogger(sqlProject);

var dacpacPath = sqlProject.GetDacpacPath();
if (!File.Exists(dacpacPath))
try
{
logger.LogError("SQL Server Database project package not found at path {DacpacPath}.", dacpacPath);
await _resourceNotificationService.PublishUpdateAsync(sqlProject,
state => state with { State = new ResourceStateSnapshot("Failed", KnownResourceStateStyles.Error) });
return;
}
var dacpacPath = sqlProject.GetDacpacPath();
if (!File.Exists(dacpacPath))
{
logger.LogError("SQL Server Database project package not found at path {DacpacPath}.", dacpacPath);
await _resourceNotificationService.PublishUpdateAsync(sqlProject,
state => state with { State = new ResourceStateSnapshot("Failed", KnownResourceStateStyles.Error) });
return;
}

var connectionString = await target.ConnectionStringExpression.GetValueAsync(cancellationToken);
if (connectionString == null)
{
logger.LogError("Failed to retrieve connection string for target database {TargetDatabaseResourceName}.", target.Name);
await _resourceNotificationService.PublishUpdateAsync(sqlProject,
state => state with { State = new ResourceStateSnapshot("Failed", KnownResourceStateStyles.Error) });
return;
}

var connectionString = await target.ConnectionStringExpression.GetValueAsync(cancellationToken);
if (connectionString == null)
{
logger.LogError("Failed to retrieve connection string for target database {TargetDatabaseResourceName}.", target.Name);
await _resourceNotificationService.PublishUpdateAsync(sqlProject,
state => state with { State = new ResourceStateSnapshot("Failed", KnownResourceStateStyles.Error) });
return;
}

await _resourceNotificationService.PublishUpdateAsync(sqlProject,
state => state with { State = new ResourceStateSnapshot("Publishing", KnownResourceStateStyles.Info) });
state => state with { State = new ResourceStateSnapshot("Publishing", KnownResourceStateStyles.Info) });

try
{
_deployer.Deploy(dacpacPath, connectionString, target.DatabaseName, logger, cancellationToken);

await _resourceNotificationService.PublishUpdateAsync(sqlProject,
Expand Down

0 comments on commit 52bb7fb

Please sign in to comment.