Spec-Zone.ru › Homebrew

Exception: ChecksumMismatchError Private

Inherits:
RuntimeError
  • Object
  • RuntimeError
  • ChecksumMismatchError
show all
Defined in:
exceptions.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Raised by Pathname#verify_checksum when verification fails.

Instance Attribute Summary collapse

  • #expected ⇒ Checksum readonly private

Class Method Summary collapse

  • .html_hint(path) ⇒ String private

    Detect downloads that are HTML pages (bot-protection challenges, rate-limit or error pages served as text/html) rather than the expected binary artifact.

Instance Method Summary collapse

  • #initialize(path, expected, actual) ⇒ void constructor private

Constructor Details

#initialize(path, expected, actual) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • path (Pathname, String)
  • expected (Checksum)
  • actual (Checksum)


923
924
925
926
927
928
929
930
931
932
933
# File 'exceptions.rb', line 923

def initialize(path, expected, actual)
  @expected = expected

  super <<~EOS
    SHA-256 mismatch
    Expected: #{Formatter.success(expected.to_s)}      Actual: #{Formatter.error(actual.to_s)}        File: #{path}    To retry an incomplete download, remove the file above.#{ChecksumMismatchError.html_hint(path)}  EOS
end

Instance Attribute Details

#expected ⇒ Checksum (readonly)

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Checksum)


920
921
922
# File 'exceptions.rb', line 920

def expected
  @expected
end

Class Method Details

.html_hint(path) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Detect downloads that are HTML pages (bot-protection challenges, rate-limit or error pages served as text/html) rather than the expected binary artifact. Returns an extra hint for the error message, or an empty string.

Parameters:

  • path (Pathname, String)

Returns:

  • (String)


939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
# File 'exceptions.rb', line 939

def self.html_hint(path)
  return "" unless path.is_a?(Pathname)
  return "" unless path.file?

  head = path.binread(512).to_s
  return "" unless head.match?(/\A\s*(?:<!doctype\s+html|<html|<\?xml[^>]*\?>\s*<html)/i)

  rm_command = if path.to_s.start_with?("#{HOMEBREW_CACHE}/")
    relative = path.relative_path_from(HOMEBREW_CACHE)
    %Q(rm "$(brew --cache)/#{relative}")
  else
    %Q(rm "#{path}")
  end

  <<~EOS
    The start of the downloaded file is HTML/XML, not a binary.
    The server may have returned a bot-protection, rate-limit or
    error page instead. Delete the file and retry:
#{rm_command}  EOS
rescue SystemCallError
  ""
end

© 2009–present Homebrew contributors
Licensed under the BSD 2-Clause License.
https://docs.brew.sh/rubydoc/ChecksumMismatchError.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API