1# TODO: the documentation in here is terrible.
2#
3# Each exception needs a brief description and the scenarios where it is
4# likely to be raised
5
6##
7# Base exception class for RubyGems.  All exception raised by RubyGems are a
8# subclass of this one.
9class Gem::Exception < RuntimeError
10  attr_accessor :source_exception
11end
12
13class Gem::CommandLineError < Gem::Exception; end
14
15class Gem::DependencyError < Gem::Exception; end
16
17class Gem::DependencyRemovalException < Gem::Exception; end
18
19##
20# Raised when attempting to uninstall a gem that isn't in GEM_HOME.
21
22class Gem::GemNotInHomeException < Gem::Exception
23  attr_accessor :spec
24end
25
26class Gem::DocumentError < Gem::Exception; end
27
28##
29# Potentially raised when a specification is validated.
30class Gem::EndOfYAMLException < Gem::Exception; end
31
32##
33# Signals that a file permission error is preventing the user from
34# operating on the given directory.
35
36class Gem::FilePermissionError < Gem::Exception
37
38  attr_reader :directory
39
40  def initialize directory
41    @directory = directory
42
43    super "You don't have write permissions for the #{directory} directory."
44  end
45
46end
47
48##
49# Used to raise parsing and loading errors
50class Gem::FormatException < Gem::Exception
51  attr_accessor :file_path
52end
53
54class Gem::GemNotFoundException < Gem::Exception; end
55
56class Gem::SpecificGemNotFoundException < Gem::GemNotFoundException
57  def initialize(name, version, errors=nil)
58    super "Could not find a valid gem '#{name}' (#{version}) locally or in a repository"
59
60    @name = name
61    @version = version
62    @errors = errors
63  end
64
65  attr_reader :name, :version, :errors
66end
67
68class Gem::InstallError < Gem::Exception; end
69
70##
71# Potentially raised when a specification is validated.
72class Gem::InvalidSpecificationException < Gem::Exception; end
73
74class Gem::OperationNotSupportedError < Gem::Exception; end
75
76##
77# Signals that a remote operation cannot be conducted, probably due to not
78# being connected (or just not finding host).
79#--
80# TODO: create a method that tests connection to the preferred gems server.
81# All code dealing with remote operations will want this.  Failure in that
82# method should raise this error.
83class Gem::RemoteError < Gem::Exception; end
84
85class Gem::RemoteInstallationCancelled < Gem::Exception; end
86
87class Gem::RemoteInstallationSkipped < Gem::Exception; end
88
89##
90# Represents an error communicating via HTTP.
91class Gem::RemoteSourceException < Gem::Exception; end
92
93class Gem::VerificationError < Gem::Exception; end
94
95##
96# Raised to indicate that a system exit should occur with the specified
97# exit_code
98
99class Gem::SystemExitException < SystemExit
100  attr_accessor :exit_code
101
102  def initialize(exit_code)
103    @exit_code = exit_code
104
105    super "Exiting RubyGems with exit_code #{exit_code}"
106  end
107
108end
109
110