Skip to content

Commit

Permalink
Generate exception error codes with Rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Sep 18, 2018
1 parent aba2439 commit 7df0916
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ begin
Rake::Task[:spec].invoke
end
end

desc 'Generate error code constants from ably-common: https://github.com/ably/ably-common/issues/32'
task :generate_error_codes do
errors_json_path = File.join(File.dirname(__FILE__), 'lib/submodules/ably-common/protocol/errors.json')
module_path = File.join(File.dirname(__FILE__), 'lib/ably/modules/exception_codes.rb')
max_length = 0

errors = JSON.parse(File.read(errors_json_path)).each_with_object({}) do |(key, val), hash|
hash[key] = val.split(/\s+/).map { |d| d.upcase.gsub(/[^a-zA-Z]+/, '') }.join('_')
end.each do |code, const_name|
max_length = [const_name.length, max_length].max
end.map do |code, const_name|
" #{const_name.ljust(max_length, ' ')} = #{code}"
end.join("\n")
module_content = <<-EOF
# This file is generated by running `rake :generate_error_codes`
# Do not manually modify this file
# Generated at: #{Time.now.utc}
#
module Ably
module Exceptions
module Codes
#{errors}
end
end
end
EOF
File.open(module_path, 'w') { |file| file.write module_content }
end
rescue LoadError
# RSpec not available
end
2 changes: 2 additions & 0 deletions lib/ably/exceptions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'ably/modules/exception_codes'

module Ably
module Exceptions
TOKEN_EXPIRED_CODE = 40140..40149
Expand Down
125 changes: 125 additions & 0 deletions lib/ably/modules/exception_codes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# This file is generated by running `rake :generate_error_codes`
# Do not manually modify this file
# Generated at: 2018-08-31 09:09:15 UTC
#
module Ably
module Exceptions
module Codes
NO_ERROR = 10000
BAD_REQUEST = 40000
INVALID_REQUEST_BODY = 40001
INVALID_PARAMETER_NAME = 40002
INVALID_PARAMETER_VALUE = 40003
INVALID_HEADER = 40004
INVALID_CREDENTIAL = 40005
INVALID_CONNECTION_ID = 40006
INVALID_MESSAGE_ID = 40007
INVALID_CONTENT_LENGTH = 40008
MAXIMUM_MESSAGE_LENGTH_EXCEEDED = 40009
INVALID_CHANNEL_NAME = 40010
STALE_RING_STATE = 40011
INVALID_CLIENT_ID = 40012
INVALID_MESSAGE_DATA_OR_ENCODING = 40013
RESOURCE_DISPOSED = 40014
INVALID_DEVICE_ID = 40015
BATCH_ERROR = 40020
INVALID_PUBLISH_REQUEST_UNSPECIFIED = 40030
INVALID_PUBLISH_REQUEST_INVALID_CLIENTSPECIFIED_ID = 40031
UNAUTHORIZED = 40100
INVALID_CREDENTIALS = 40101
INCOMPATIBLE_CREDENTIALS = 40102
INVALID_USE_OF_BASIC_AUTH_OVER_NONTLS_TRANSPORT = 40103
TIMESTAMP_NOT_CURRENT = 40104
NONCE_VALUE_REPLAYED = 40105
UNABLE_TO_OBTAIN_CREDENTIALS_FROM_GIVEN_PARAMETERS = 40106
ACCOUNT_DISABLED = 40110
ACCOUNT_RESTRICTED_CONNECTION_LIMITS_EXCEEDED = 40111
ACCOUNT_BLOCKED_MESSAGE_LIMITS_EXCEEDED = 40112
ACCOUNT_BLOCKED = 40113
ACCOUNT_RESTRICTED_CHANNEL_LIMITS_EXCEEDED = 40114
APPLICATION_DISABLED = 40120
KEY_ERROR_UNSPECIFIED = 40130
KEY_REVOKED = 40131
KEY_EXPIRED = 40132
KEY_DISABLED = 40133
TOKEN_ERROR_UNSPECIFIED = 40140
TOKEN_REVOKED = 40141
TOKEN_EXPIRED = 40142
TOKEN_UNRECOGNISED = 40143
INVALID_JWT_FORMAT = 40144
INVALID_TOKEN_FORMAT = 40145
CONNECTION_BLOCKED_LIMITS_EXCEEDED = 40150
OPERATION_NOT_PERMITTED_WITH_PROVIDED_CAPABILITY = 40160
ERROR_FROM_CLIENT_TOKEN_CALLBACK = 40170
FORBIDDEN = 40300
ACCOUNT_DOES_NOT_PERMIT_TLS_CONNECTION = 40310
OPERATION_REQUIRES_TLS_CONNECTION = 40311
APPLICATION_REQUIRES_AUTHENTICATION = 40320
NOT_FOUND = 40400
METHOD_NOT_ALLOWED = 40500
RATE_LIMIT_EXCEEDED_NONFATAL_REQUEST_REJECTED_UNSPECIFIED = 42910
MAX_PERCONNECTION_PUBLISH_RATE_LIMIT_EXCEEDED_NONFATAL_UNABLE_TO_PUBLISH_MESSAGE = 42911
RATE_LIMIT_EXCEEDED_FATAL = 42920
MAX_PERCONNECTION_PUBLISH_RATE_LIMIT_EXCEEDED_FATAL_CLOSING_CONNECTION = 42921
INTERNAL_ERROR = 50000
INTERNAL_CHANNEL_ERROR = 50001
INTERNAL_CONNECTION_ERROR = 50002
TIMEOUT_ERROR = 50003
REQUEST_FAILED_DUE_TO_OVERLOADED_INSTANCE = 50004
REACTOR_OPERATION_FAILED = 70000
REACTOR_OPERATION_FAILED_POST_OPERATION_FAILED = 70001
REACTOR_OPERATION_FAILED_POST_OPERATION_RETURNED_UNEXPECTED_CODE = 70002
REACTOR_OPERATION_FAILED_MAXIMUM_NUMBER_OF_CONCURRENT_INFLIGHT_REQUESTS_EXCEEDED = 70003
EXCHANGE_ERROR_UNSPECIFIED = 71000
FORCED_REATTACHMENT_DUE_TO_PERMISSIONS_CHANGE = 71001
EXCHANGE_PUBLISHER_ERROR_UNSPECIFIED = 71100
NO_SUCH_PUBLISHER = 71101
PUBLISHER_NOT_ENABLED_AS_AN_EXCHANGE_PUBLISHER = 71102
EXCHANGE_PRODUCT_ERROR_UNSPECIFIED = 71200
NO_SUCH_PRODUCT = 71201
PRODUCT_DISABLED = 71202
NO_SUCH_CHANNEL_IN_THIS_PRODUCT = 71203
EXCHANGE_SUBSCRIPTION_ERROR_UNSPECIFIED = 71300
SUBSCRIPTION_DISABLED = 71301
REQUESTER_HAS_NO_SUBSCRIPTION_TO_THIS_PRODUCT = 71302
CONNECTION_FAILED = 80000
CONNECTION_FAILED_NO_COMPATIBLE_TRANSPORT = 80001
CONNECTION_SUSPENDED = 80002
DISCONNECTED = 80003
ALREADY_CONNECTED = 80004
INVALID_CONNECTION_ID_REMOTE_NOT_FOUND = 80005
UNABLE_TO_RECOVER_CONNECTION_MESSAGES_EXPIRED = 80006
UNABLE_TO_RECOVER_CONNECTION_MESSAGE_LIMIT_EXCEEDED = 80007
UNABLE_TO_RECOVER_CONNECTION_CONNECTION_EXPIRED = 80008
CONNECTION_NOT_ESTABLISHED_NO_TRANSPORT_HANDLE = 80009
INVALID_OPERATION_INVALID_TRANSPORT_HANDLE = 80010
UNABLE_TO_RECOVER_CONNECTION_INCOMPATIBLE_AUTH_PARAMS = 80011
UNABLE_TO_RECOVER_CONNECTION_INVALID_OR_UNSPECIFIED_CONNECTION_SERIAL = 80012
PROTOCOL_ERROR = 80013
CONNECTION_TIMED_OUT = 80014
INCOMPATIBLE_CONNECTION_PARAMETERS = 80015
OPERATION_ON_SUPERSEDED_TRANSPORT = 80016
CONNECTION_CLOSED = 80017
INVALID_CONNECTION_ID_INVALID_FORMAT = 80018
CLIENT_CONFIGURED_AUTHENTICATION_PROVIDER_REQUEST_FAILED = 80019
CONTINUITY_LOSS_DUE_TO_MAXIMUM_SUBSCRIBE_MESSAGE_RATE_EXCEEDED = 80020
CLIENT_RESTRICTION_NOT_SATISFIED = 80030
CHANNEL_OPERATION_FAILED = 90000
CHANNEL_OPERATION_FAILED_INVALID_CHANNEL_STATE = 90001
CHANNEL_OPERATION_FAILED_EPOCH_EXPIRED_OR_NEVER_EXISTED = 90002
UNABLE_TO_RECOVER_CHANNEL_MESSAGES_EXPIRED = 90003
UNABLE_TO_RECOVER_CHANNEL_MESSAGE_LIMIT_EXCEEDED = 90004
UNABLE_TO_RECOVER_CHANNEL_NO_MATCHING_EPOCH = 90005
UNABLE_TO_RECOVER_CHANNEL_UNBOUNDED_REQUEST = 90006
CHANNEL_OPERATION_FAILED_NO_RESPONSE_FROM_SERVER = 90007
MAXIMUM_NUMBER_OF_CHANNELS_PER_CONNECTION_EXCEEDED = 90010
UNABLE_TO_ENTER_PRESENCE_CHANNEL_NO_CLIENTID = 91000
UNABLE_TO_ENTER_PRESENCE_CHANNEL_INVALID_CHANNEL_STATE = 91001
UNABLE_TO_LEAVE_PRESENCE_CHANNEL_THAT_IS_NOT_ENTERED = 91002
UNABLE_TO_ENTER_PRESENCE_CHANNEL_MAXIMUM_MEMBER_LIMIT_EXCEEDED = 91003
UNABLE_TO_AUTOMATICALLY_REENTER_PRESENCE_CHANNEL = 91004
PRESENCE_STATE_IS_OUT_OF_SYNC = 91005
MEMBER_IMPLICITLY_LEFT_PRESENCE_CHANNEL_CONNECTION_CLOSED = 91100
end
end
end
2 changes: 1 addition & 1 deletion lib/submodules/ably-common

0 comments on commit 7df0916

Please sign in to comment.