Fix dev-db.ps1 status to exit cleanly when container is absent
docker inspect exits non-zero when the container is missing; under $ErrorActionPreference='Stop' that propagated and made `dev-db.ps1 status` exit 1 even though the script printed the right output. Swallow the inner exit code locally so callers see exit 0.
This commit is contained in:
+7
-2
@@ -34,8 +34,13 @@ $Image = 'postgres:17'
|
||||
$ConnectionString = 'Host=localhost;Database=yeschef;Username=yeschef;Password=yeschef'
|
||||
|
||||
function Get-ContainerState {
|
||||
$state = docker inspect --format '{{.State.Status}}' $Name 2>$null
|
||||
if ($LASTEXITCODE -ne 0) { return 'absent' }
|
||||
# docker inspect exits non-zero when the container is missing; swallow
|
||||
# that so $ErrorActionPreference='Stop' doesn't abort the script and
|
||||
# so the caller's exit code stays clean.
|
||||
$state = & docker inspect --format '{{.State.Status}}' $Name 2>$null
|
||||
$code = $LASTEXITCODE
|
||||
$global:LASTEXITCODE = 0
|
||||
if ($code -ne 0) { return 'absent' }
|
||||
return $state
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user