From 99aef587b0ed24539ef5eb78ab689ffff5640e6f Mon Sep 17 00:00:00 2001 From: Matthew O'Riordan Date: Sun, 24 Aug 2025 09:18:05 +0200 Subject: [PATCH] Update error messages for better user experience This commit updates error message strings to be more descriptive and user-friendly, providing clearer guidance on what went wrong and how to resolve issues. Changes include: lib/ably/models/message_encoders/cipher.rb | 6 ++++-- lib/ably/modules/conversions.rb | 3 ++- lib/ably/realtime/client/incoming_message_dispatcher.rb | 3 ++- lib/ably/realtime/presence.rb | 3 ++- lib/submodules/ably-common | 0 5 files changed, 10 insertions(+), 5 deletions(-) These improvements are part of an ongoing initiative to enhance error messaging across all Ably SDKs and services for better developer experience. For more context, see: https://github.com/ably/ably-os --- lib/ably/models/message_encoders/cipher.rb | 6 ++++-- lib/ably/modules/conversions.rb | 3 ++- lib/ably/realtime/client/incoming_message_dispatcher.rb | 3 ++- lib/ably/realtime/presence.rb | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/ably/models/message_encoders/cipher.rb b/lib/ably/models/message_encoders/cipher.rb index 112476871..67f20a2f2 100644 --- a/lib/ably/models/message_encoders/cipher.rb +++ b/lib/ably/models/message_encoders/cipher.rb @@ -25,10 +25,12 @@ def encode(message, channel_options) add_encoding_to_message "#{ENCODING_ID}+#{crypto.cipher_params.cipher_type.downcase}", message end rescue ArgumentError => e - raise Ably::Exceptions::CipherError.new(e.message, nil, 92005) + # ably-os:inline-error-update:92005:2025-08-22:e8u Original: "#{e.message}" + raise Ably::Exceptions::CipherError.new("Encryption failed due to configuration error: #{e.message}. Check your cipher key format and message data", nil, 92005) rescue RuntimeError => e if e.message.match(/unsupported cipher algorithm/i) - raise Ably::Exceptions::CipherError.new(e.message, nil, 92004) + # ably-os:inline-error-update:92004:2025-08-22:e8u Original: "#{e.message}" + raise Ably::Exceptions::CipherError.new("Unsupported cipher algorithm specified. #{e.message}. Supported algorithms: AES-128-CBC, AES-256-CBC", nil, 92004) else raise e end diff --git a/lib/ably/modules/conversions.rb b/lib/ably/modules/conversions.rb index 9561afc5d..6ef166b94 100644 --- a/lib/ably/modules/conversions.rb +++ b/lib/ably/modules/conversions.rb @@ -113,7 +113,8 @@ def ensure_supported_payload(payload) payload.kind_of?(Array) || payload.nil? - raise Ably::Exceptions::UnsupportedDataType.new('Invalid data payload', 400, Ably::Exceptions::Codes::INVALID_MESSAGE_DATA_OR_ENCODING) + # ably-os:inline-error-update:40013:2025-08-22:e8u Original: "Invalid data payload" + raise Ably::Exceptions::UnsupportedDataType.new("Invalid data payload: #{payload.class} is not supported. Use String, Hash, Array, or nil", 400, Ably::Exceptions::Codes::INVALID_MESSAGE_DATA_OR_ENCODING) end # Converts the name, data, attributes into the array of Message objects diff --git a/lib/ably/realtime/client/incoming_message_dispatcher.rb b/lib/ably/realtime/client/incoming_message_dispatcher.rb index 435d70660..616a7f35a 100644 --- a/lib/ably/realtime/client/incoming_message_dispatcher.rb +++ b/lib/ably/realtime/client/incoming_message_dispatcher.rb @@ -141,7 +141,8 @@ def dispatch_protocol_message(*args) client.auth.authorize else - error = Ably::Exceptions::ProtocolError.new("Protocol Message Action #{protocol_message.action} is unsupported by this MessageDispatcher", 400, Ably::Exceptions::Codes::PROTOCOL_ERROR) + # ably-os:inline-error-update:80013:2025-08-22:e8u Original: "Protocol Message Action #{protocol_message.action} is unsupported by this MessageDispatcher" + error = Ably::Exceptions::ProtocolError.new("Protocol error: unsupported action '#{protocol_message.action}' received. Check your SDK version and protocol compatibility", 400, Ably::Exceptions::Codes::PROTOCOL_ERROR) logger.fatal error.message end end diff --git a/lib/ably/realtime/presence.rb b/lib/ably/realtime/presence.rb index 5d66b7e99..ac0263bfc 100644 --- a/lib/ably/realtime/presence.rb +++ b/lib/ably/realtime/presence.rb @@ -349,7 +349,8 @@ def sync_complete? def send_presence_protocol_message(presence_action, client_id, data, id = nil) presence_message = create_presence_message(presence_action, client_id, data, id) unless presence_message.client_id - raise Ably::Exceptions::Standard.new('Unable to enter create presence message without a client_id', 400, Ably::Exceptions::Codes::UNABLE_TO_ENTER_PRESENCE_CHANNEL_NO_CLIENTID) + # ably-os:inline-error-update:91000:2025-08-22:e8u Original: "Unable to enter create presence message without a client_id" + raise Ably::Exceptions::Standard.new('Unable to enter presence channel without a client_id', 400, Ably::Exceptions::Codes::UNABLE_TO_ENTER_PRESENCE_CHANNEL_NO_CLIENTID) end protocol_message = {