1#--
2# This file contains all the various exceptions and other errors that are used
3# inside of RubyGems.
4#
5# DOC: Confirm _all_
6#++
7
8module Gem
9  ##
10  # Raised when RubyGems is unable to load or activate a gem.  Contains the
11  # name and version requirements of the gem that either conflicts with
12  # already activated gems or that RubyGems is otherwise unable to activate.
13
14  class LoadError < ::LoadError
15    # Name of gem
16    attr_accessor :name
17
18    # Version requirement of gem
19    attr_accessor :requirement
20  end
21
22  # FIX: does this need to exist? The subclass is the only other reference
23  # I can find.
24  class ErrorReason; end
25
26  # Generated when trying to lookup a gem to indicate that the gem
27  # was found, but that it isn't usable on the current platform.
28  #
29  # fetch and install read these and report them to the user to aid
30  # in figuring out why a gem couldn't be installed.
31  #
32  class PlatformMismatch < ErrorReason
33
34    ##
35    # the name of the gem
36    attr_reader :name
37
38    ##
39    # the version
40    attr_reader :version
41
42    ##
43    # The platforms that are mismatched
44    attr_reader :platforms
45
46    def initialize(name, version)
47      @name = name
48      @version = version
49      @platforms = []
50    end
51
52    ##
53    # append a platform to the list of mismatched platforms.
54    #
55    # Platforms are added via this instead of injected via the constructor
56    # so that we can loop over a list of mismatches and just add them rather
57    # than perform some kind of calculation mismatch summary before creation.
58    def add_platform(platform)
59      @platforms << platform
60    end
61
62    ##
63    # A wordy description of the error.
64    def wordy
65      "Found %s (%s), but was for platform%s %s" %
66        [@name,
67         @version,
68         @platforms.size == 1 ? '' : 's',
69         @platforms.join(' ,')]
70    end
71  end
72
73  ##
74  # An error that indicates we weren't able to fetch some
75  # data from a source
76
77  class SourceFetchProblem < ErrorReason
78    def initialize(source, error)
79      @source = source
80      @error = error
81    end
82
83    attr_reader :source, :error
84
85    def wordy
86      "Unable to download data from #{@source.uri} - #{@error.message}"
87    end
88  end
89end
90