Skip to content

Commit dce220e

Browse files
committed
Cask::Audit: fix key not found: :latest error
`Cask::Audit.audit_livecheck_version` can raise a `key not found: :latest` error when a hash from livecheck's `latest_version` method doesn't have a `:latest` value. This error means that livecheck was unable to identify the latest upstream version but it can only be understood if the reader knows how this audit is implemented (and it may also depend on knowing the structure of livecheck's `latest_version` hash). Without that knowledge, the error doesn't make it clear which audit is failing and why. This addresses the issue by using `nil` as the default value for this `fetch` call and accounting for a `nil` `latest_version` value. This allows the audit to surface the usual "Version '1.2.3' differs from '' retrieved by livecheck" failure, which makes it more clear that livecheck isn't returning a version.
1 parent 4343324 commit dce220e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Library/Homebrew/cask/audit.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,9 @@ def audit_livecheck_version
755755
latest_version = Homebrew::Livecheck.latest_version(
756756
cask,
757757
referenced_formula_or_cask: referenced_cask,
758-
)&.fetch(:latest)
758+
)&.fetch(:latest, nil)
759759

760-
return :auto_detected if cask.version.to_s == latest_version.to_s
760+
return :auto_detected if latest_version && (cask.version.to_s == latest_version.to_s)
761761

762762
add_error "Version '#{cask.version}' differs from '#{latest_version}' retrieved by livecheck."
763763

0 commit comments

Comments
 (0)