Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scoop-update): Properly summarize failed updates #177

Merged
merged 3 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions bin/update-supporting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ foreach ($sup in $Sups) {
Invoke-ManifestScript -Manifest $manifest -ScriptName 'pre_install' -Architecture $architecture
} catch {
++$problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message

continue
}
Expand Down
22 changes: 22 additions & 0 deletions lib/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ function New-IssuePrompt {
param([String] $Application, [String] $Bucket, [String] $Title, [String[]] $Body)

$Bucket = $Bucket.Trim()
# TODO: Adopt-ManifestResolveInformation
$app, $manifest, $Bucket, $url = Find-Manifest $Application $Bucket
$url = known_bucket_repo $Bucket
$bucketPath = Join-Path $SCOOP_BUCKETS_DIRECTORY $Bucket
Expand Down Expand Up @@ -357,6 +358,27 @@ function New-IssuePrompt {
Write-UserMessage -Message "$msg`n$url" -Color 'DarkRed'
}

function New-IssuePromptFromException {
<#
.SYNOPSIS
Wrapper for handling <Title>|-<Body> exception messages with support for promping user with according link to create a new issue.
#>
param(
[String] $ExceptionMessage,
[AllowNull()]
[String] $Application,
[AllowNull()]
[String] $Bucket
)

process {
$title, $body = $ExceptionMessage -split '\|-'
if (!$body) { $body = $title }
if ($body -ne 'Ignore') { Write-UserMessage -Message $body -Err }
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $Application -Bucket $Bucket -Title $title -Body $body }
}
}

function Get-NotePropertyEnumerator {
<#
.SYNOPSIS
Expand Down
9 changes: 4 additions & 5 deletions lib/Update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,13 @@ function Update-App {

# TODO: Could this ever happen?
if (!$Force -and ($oldVersion -eq $version)) {
if (!$quiet) { Write-UserMessage -Message "The Latest version of '$App' ($version) is already installed." -Warning }
return
throw [ScoopException] "The Latest version of '$App' ($version) is already installed." # TerminatingError thrown
}

# TODO:???
# TODO: Case when bucket no longer have this application?
if (!$version) {
Write-UserMessage -Message "No manifest available for '$App'" -Err
return
throw [ScoopException] "No manifest available for '$App'" # TerminatingError thrown
}

$manifest = manifest $App $bucket $url
Expand Down Expand Up @@ -291,7 +289,7 @@ function Update-App {
#endregion Workaround of #2220

$result = Uninstall-ScoopApplication -App $App -Global:$Global
if ($result -eq $false) { return }
if ($result -eq $false) { throw [ScoopException] 'Ignore' }

# Rename current version to .old if same version is installed
if ($Force -and ($oldVersion -eq $version)) {
Expand All @@ -307,6 +305,7 @@ function Update-App {
}
}

# TODO: Adopt Resolve-ManifestInformation???
$toUpdate = if ($install.url) { $install.url } else { "$bucket/$App" }

# Error catching should be handled on upper scope
Expand Down
5 changes: 1 addition & 4 deletions libexec/scoop-cat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@ foreach ($app in $Applications) {
$resolved = Resolve-ManifestInformation -ApplicationQuery $app
} catch {
++$Problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message

continue
}
Expand Down
15 changes: 3 additions & 12 deletions libexec/scoop-download.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ foreach ($app in $application) {
$resolved = Resolve-ManifestInformation -ApplicationQuery $app
} catch {
++$problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message

continue
}
Expand Down Expand Up @@ -77,11 +74,8 @@ foreach ($app in $application) {
++$problems
}

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body }
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $appName -Bucket $bucket

continue
}
Expand Down Expand Up @@ -115,11 +109,8 @@ foreach ($app in $application) {
++$problems
}

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $appName -Bucket $bucket -Title $title -Body $body }
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $appName -Bucket $bucket

continue
}
Expand Down
4 changes: 1 addition & 3 deletions libexec/scoop-home.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ $resolved = $null
try {
$resolved = Resolve-ManifestInformation -ApplicationQuery $Application
} catch {
$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message

$ExitCode = 3
}
Expand Down
23 changes: 12 additions & 11 deletions libexec/scoop-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ if (!$independent) {
try {
$apps = install_order $apps $architecture # Add dependencies
} catch {
$title, $body = $_.Exception.Message -split '\|-'
Write-UserMessage -Message $body -Err
if ($title -ne 'Ignore') {
New-IssuePrompt -Application $app -Title $title -Body $body
}
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message
}
}

Expand Down Expand Up @@ -156,6 +152,7 @@ foreach ($app in $apps) {
continue
}

# TODO: Resolve-ManifestInformation
$cleanApp, $bucket = parse_app $app

# Prevent checking of already installed applications if specific version was provided.
Expand All @@ -178,20 +175,24 @@ foreach ($app in $apps) {
# Register failed dependencies
if ($explicit_apps -notcontains $app) { $failedDependencies += $app } else { $failedApplications += $app }

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $cleanApp -Bucket $bucket -Title $title -Body $body }
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $cleanApp -Bucket $bucket

continue
}
}

show_suggestions $suggested

if ($failedApplications) { Write-UserMessage -Message "These applications failed to install: $($failedApplications -join ', ')" -Err }
if ($failedDependencies) { Write-UserMessage -Message "These dependencies failed to install: $($failedDependencies -join ', ')" -Err }
if ($failedApplications) {
$pl = pluralize $failedApplications.Count 'This application' 'These applications'
Write-UserMessage -Message "$pl failed to install: $($failedApplications -join ', ')" -Err
}

if ($failedDependencies) {
$pl = pluralize $failedDependencies.Count 'This dependency' 'These dependencies'
Write-UserMessage -Message "$pl failed to install: $($failedDependencies -join ', ')" -Err
}

if ($problems -gt 0) { $exitCode = 10 + $problems }

Expand Down
6 changes: 1 addition & 5 deletions libexec/scoop-uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ foreach ($explode in $Applications) {
$result = Uninstall-ScoopApplication -App $app -Global:$gl -Purge:$Purge -Older
} catch {
++$Problems

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $app -Bucket $bucket -Title $title -Body $body }
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $app -Bucket $bucket

continue
}
Expand Down
14 changes: 5 additions & 9 deletions libexec/scoop-update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,17 @@ if (!$Applications) {
Update-App -App $out[0] -Global:$out[1] -Suggested @{ } -Quiet:$Quiet -Independent:$Independent -SkipCache:(!$UseCache) -SkipHashCheck:(!$CheckHash)
} catch {
++$Problems

$failedApplications += $out[0]

$title, $body = $_.Exception.Message -split '\|-'
if (!$body) { $body = $title }
Write-UserMessage -Message $body -Err
debug $_.InvocationInfo
if ($title -ne 'Ignore' -and ($title -ne $body)) { New-IssuePrompt -Application $out[0] -Bucket $out[2] -Title $title -Body $body }

continue
New-IssuePromptFromException -ExceptionMessage $_.Exception.Message -Application $out[0] -Bucket $out[2]
}
}
}

if ($failedApplications) { Write-UserMessage -Message "These applications failed to update: $($failedApplications -join ', ')" -Err }
if ($failedApplications) {
$pl = pluralize $failedApplications.Count 'This application' 'These applications'
Write-UserMessage -Message "$pl failed to update: $($failedApplications -join ', ')" -Err
}

if ($Problems -gt 0) { $ExitCode = 10 + $Problems }

Expand Down