Skip to content

Commit 03f0d51

Browse files
committed
Moved all custom errors into a single file and into the Concurrent module.
1 parent 33fd334 commit 03f0d51

File tree

15 files changed

+60
-37
lines changed

15 files changed

+60
-37
lines changed

lib/concurrent.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
require 'concurrent/dataflow'
1414
require 'concurrent/delay'
1515
require 'concurrent/dereferenceable'
16+
require 'concurrent/errors'
1617
require 'concurrent/exchanger'
1718
require 'concurrent/future'
1819
require 'concurrent/ivar'

lib/concurrent/actor/postable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def post?(*message)
5757

5858
def post!(seconds, *message)
5959
raise ArgumentError.new('empty message') if message.empty?
60-
raise Concurrent::Runnable::LifecycleError unless ready?
60+
raise Concurrent::LifecycleError unless ready?
6161
raise Concurrent::TimeoutError if seconds.to_f <= 0.0
6262
event = Event.new
6363
cback = Queue.new

lib/concurrent/async.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
require 'thread'
22
require 'concurrent/configuration'
33
require 'concurrent/delay'
4+
require 'concurrent/errors'
45
require 'concurrent/ivar'
56
require 'concurrent/future'
67
require 'concurrent/executor/thread_pool_executor'
78

89
module Concurrent
910

10-
InitializationError = Class.new(StandardError)
11-
1211
# A mixin module that provides simple asynchronous behavior to any standard
1312
# class/object or object.
1413
#

lib/concurrent/configuration.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
require 'thread'
22
require 'concurrent/delay'
3+
require 'concurrent/errors'
34
require 'concurrent/executor/thread_pool_executor'
45
require 'concurrent/executor/timer_set'
56
require 'concurrent/utility/processor_count'
67

78
module Concurrent
89

9-
# An error class to be raised when errors occur during configuration.
10-
ConfigurationError = Class.new(StandardError)
11-
1210
# A gem-level configuration object.
1311
class Configuration
1412

@@ -55,7 +53,7 @@ def global_timer_set
5553
#
5654
# @return [ThreadPoolExecutor] the new thread pool
5755
#
58-
# @raise [ConfigurationError] if this thread pool has already been set
56+
# @raise [Concurrent::ConfigurationError] if this thread pool has already been set
5957
def global_task_pool=(executor)
6058
@global_task_pool.reconfigure { executor } or
6159
raise ConfigurationError.new('global task pool was already set')
@@ -74,7 +72,7 @@ def global_task_pool=(executor)
7472
#
7573
# @return [ThreadPoolExecutor] the new thread pool
7674
#
77-
# @raise [ConfigurationError] if this thread pool has already been set
75+
# @raise [Concurrent::ConfigurationError] if this thread pool has already been set
7876
def global_operation_pool=(executor)
7977
@global_operation_pool.reconfigure { executor } or
8078
raise ConfigurationError.new('global operation pool was already set')

lib/concurrent/errors.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module Concurrent
2+
3+
# Raised when a complex and atomic operation, such as a transaction,
4+
# is aborted prior to completion.
5+
AbortError = Class.new(StandardError)
6+
7+
# Raised when errors occur during configuration.
8+
ConfigurationError = Class.new(StandardError)
9+
10+
# Raised when a lifecycle method (such as `stop`) is called in an improper
11+
# sequence or when the object is in an inappropriate state.
12+
LifecycleError = Class.new(StandardError)
13+
14+
# Raised when an object's methods are called when it has not been
15+
# properly initialized.
16+
InitializationError = Class.new(StandardError)
17+
18+
# Raised when an object with a start/stop lifecycle has been started an
19+
# excessive number of times. Often used in conjunction with a restart
20+
# policy or strategy.
21+
MaxRestartFrequencyError = Class.new(StandardError)
22+
23+
# Raised when an attempt is made to modify an immutable object
24+
# (such as an `IVar`) after its final state has been set.
25+
MultipleAssignmentError = Class.new(StandardError)
26+
27+
# Raised by an `Executor` when it is unable to process a given task,
28+
# possibly because of a reject policy or other internal error.
29+
RejectedExecutionError = Class.new(StandardError)
30+
31+
# Raised when an operation times out.
32+
TimeoutError = Class.new(StandardError)
33+
34+
end

lib/concurrent/executor/executor.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1+
require 'concurrent/errors'
12
require 'concurrent/atomic/event'
23

34
module Concurrent
45

5-
# An exception class raised when the maximum queue size is reached and the
6-
# `overflow_policy` is set to `:abort`.
7-
RejectedExecutionError = Class.new(StandardError)
8-
96
module Executor
107

118
# Submit a task to the executor for asynchronous processing.

lib/concurrent/ivar.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'thread'
22

3+
require 'concurrent/errors'
34
require 'concurrent/obligation'
45
require 'concurrent/observable'
56

@@ -22,10 +23,6 @@ module Concurrent
2223
# ivar.set 2 # would now be an error
2324
class IVar
2425

25-
# Error that indicates that an `IVar` was set twice. Each `IVar` can only
26-
# be set once - they are immutable.
27-
MultipleAssignmentError = Class.new(StandardError)
28-
2926
include Obligation
3027
include Observable
3128

@@ -85,15 +82,15 @@ def add_observer(observer = nil, func = :update, &block)
8582
# Set the `IVar` to a value and wake or notify all threads waiting on it.
8683
#
8784
# @param [Object] value the value to store in the `IVar`
88-
# @raise [MultipleAssignmentError] if the `IVar` has already been set or otherwise completed
85+
# @raise [Concurrent::MultipleAssignmentError] if the `IVar` has already been set or otherwise completed
8986
def set(value)
9087
complete(true, value, nil)
9188
end
9289

9390
# Set the `IVar` to failed due to some error and wake or notify all threads waiting on it.
9491
#
9592
# @param [Object] reason for the failure
96-
# @raise [MultipleAssignmentError] if the `IVar` has already been set or otherwise completed
93+
# @raise [Concurrent::MultipleAssignmentError] if the `IVar` has already been set or otherwise completed
9794
def fail(reason = StandardError.new)
9895
complete(false, nil, reason)
9996
end

lib/concurrent/runnable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
require 'thread'
22

3+
require 'concurrent/errors'
4+
35
module Concurrent
46

57
module Runnable
68

7-
LifecycleError = Class.new(StandardError)
8-
99
class Context
1010
attr_reader :runner, :thread
1111
def initialize(runner)

lib/concurrent/supervisor.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'thread'
22

3+
require 'concurrent/errors'
34
require 'concurrent/runnable'
45

56
module Concurrent
@@ -15,8 +16,6 @@ class Supervisor
1516
CHILD_TYPES = [:worker, :supervisor]
1617
CHILD_RESTART_OPTIONS = [:permanent, :transient, :temporary]
1718

18-
MaxRestartFrequencyError = Class.new(StandardError)
19-
2019
WorkerContext = Struct.new(:worker, :type, :restart) do
2120
attr_accessor :thread
2221
attr_accessor :terminated

lib/concurrent/tvar.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'set'
22

3+
require 'concurrent/errors'
34
require 'concurrent/atomic/thread_local_var'
45

56
module Concurrent
@@ -109,7 +110,7 @@ def atomically
109110

110111
begin
111112
result = yield
112-
rescue Transaction::AbortError => e
113+
rescue Concurrent::AbortError => e
113114
transaction.abort
114115
result = Transaction::ABORTED
115116
rescue => e
@@ -138,7 +139,7 @@ def atomically
138139

139140
# Abort a currently running transaction - see `Concurrent::atomically`.
140141
def abort_transaction
141-
raise Transaction::AbortError.new
142+
raise Concurrent::AbortError.new
142143
end
143144

144145
module_function :atomically, :abort_transaction
@@ -154,8 +155,6 @@ class Transaction
154155
ReadLogEntry = Struct.new(:tvar, :version)
155156
UndoLogEntry = Struct.new(:tvar, :value)
156157

157-
AbortError = Class.new(StandardError)
158-
159158
def initialize
160159
@write_set = Set.new
161160
@read_log = []

0 commit comments

Comments
 (0)