Skip to content

Commit 5c5e557

Browse files
Merge pull request #1105 from erikdarlingdata/feature/code-review-installer
Fix CLI installer version-detection / failure-handling (chunk 4)
2 parents 2bff544 + 4024392 commit 5c5e557

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

Installer.Core/InstallationService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,7 @@ public static string GenerateSummaryReport(
830830
public static async Task<string?> GetInstalledVersionAsync(
831831
string connectionString,
832832
IProgress<InstallationProgress>? progress = null,
833+
bool throwOnError = false,
833834
CancellationToken cancellationToken = default)
834835
{
835836
LogDebug(progress, "GetInstalledVersionAsync: checking for existing installation");
@@ -890,11 +891,17 @@ rather than treating this as a fresh install (which would drop the database).
890891
catch (SqlException ex)
891892
{
892893
LogDebug(progress, $"GetInstalledVersionAsync: SqlException — {ex.Number}: {ex.Message}");
894+
/* The installer passes throwOnError=true so a transient/permission error can't be
895+
mistaken for "database absent" and silently trigger a fresh install over an
896+
existing database (no upgrades, then logged as SUCCESS — the #538 hazard). Soft
897+
callers (Dashboard version column, adversarial tests) keep the null fallback. */
898+
if (throwOnError) throw;
893899
return null;
894900
}
895901
catch (Exception ex)
896902
{
897903
LogDebug(progress, $"GetInstalledVersionAsync: {ex.GetType().Name}{ex.Message}");
904+
if (throwOnError) throw;
898905
return null;
899906
}
900907
}
@@ -1047,6 +1054,14 @@ rather than treating this as a fresh install (which would drop the database).
10471054

10481055
totalSuccessCount += success;
10491056
totalFailureCount += failure;
1057+
1058+
/* Stop at the first failed hop. Later hops assume this one's schema changes applied;
1059+
running them against a partially-upgraded database compounds the damage. The caller
1060+
aborts the whole install when totalFailureCount > 0. */
1061+
if (failure > 0)
1062+
{
1063+
break;
1064+
}
10501065
}
10511066

10521067
return (totalSuccessCount, totalFailureCount, upgrades.Count);

Installer.Core/Models/InstallationResultCode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public enum InstallationResultCode
1414
VersionCheckFailed = 5,
1515
SqlFilesNotFound = 6,
1616
UninstallFailed = 7,
17-
UpgradesFailed = 8
17+
UpgradesFailed = 8,
18+
CleanInstallFailed = 9
1819
}

Installer/Program.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,22 @@ Ask about clean install (automated mode preserves database unless --reinstall fl
533533
}
534534
catch (Exception ex)
535535
{
536-
Console.WriteLine($"Warning: Could not complete cleanup: {ex.Message}");
537-
Console.WriteLine("Continuing with installation...");
536+
Console.WriteLine();
537+
Console.WriteLine("================================================================================");
538+
WriteError($"Clean install failed: {ex.Message}");
539+
Console.WriteLine("The database was NOT dropped/reset, so continuing would install over an");
540+
Console.WriteLine("inconsistent database with neither a clean drop nor upgrade scripts. Aborting.");
541+
Console.WriteLine("Fix the error above and re-run the installer.");
542+
Console.WriteLine("================================================================================");
543+
544+
string errorLogPath = WriteErrorLog(ex, serverName!, infoVersion);
545+
Console.WriteLine($"Error log written to: {errorLogPath}");
546+
547+
if (!automatedMode)
548+
{
549+
WaitForExit();
550+
}
551+
return (int)InstallationResultCode.CleanInstallFailed;
538552
}
539553
}
540554
else
@@ -545,7 +559,7 @@ Ask about clean install (automated mode preserves database unless --reinstall fl
545559
string? currentVersion = null;
546560
try
547561
{
548-
currentVersion = await InstallationService.GetInstalledVersionAsync(connectionString).ConfigureAwait(false);
562+
currentVersion = await InstallationService.GetInstalledVersionAsync(connectionString, throwOnError: true).ConfigureAwait(false);
549563
}
550564
catch (Exception ex)
551565
{

0 commit comments

Comments
 (0)