From 6ad054264a2c84fc2502c64c83c18d20b1fee00d Mon Sep 17 00:00:00 2001 From: Omar Nasser Date: Sun, 24 Aug 2025 10:31:55 +0300 Subject: [PATCH 1/2] Return array of devfile errors rather than a single string --- .../main_integration_spec.rb | 4 ++-- .../create/main_integration_spec.rb | 2 +- lib/gitlab/fp/message_support.rb | 20 ++++++++++++++----- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/ee/spec/lib/remote_development/devfile_operations/main_integration_spec.rb b/ee/spec/lib/remote_development/devfile_operations/main_integration_spec.rb index 5b047ff3321a71..995311b747ef0c 100644 --- a/ee/spec/lib/remote_development/devfile_operations/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/devfile_operations/main_integration_spec.rb @@ -65,7 +65,7 @@ it "returns failure" do expect(response).to eq({ status: :error, - message: "Devfile restrictions failed: No components present in devfile", + message: ["Devfile restrictions failed: No components present in devfile"], reason: :bad_request }) end @@ -81,7 +81,7 @@ "Endpoint name 'gl-example-invalid-second-endpoint' of component 'example-invalid-second-component' " \ "must not start with 'gl-'" err2 = "Event 'gl-example' of type 'preStart' must not start with 'gl-'" - expected_message = "Devfile restrictions failed: #{err1}, #{err2}" + expected_message = ["Devfile restrictions failed: #{err1}", "Devfile restrictions failed: #{err2}"] expect(response).to eq({ status: :error, diff --git a/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb b/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb index 76054104727244..900c78185105b2 100644 --- a/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb +++ b/ee/spec/lib/remote_development/workspace_operations/create/main_integration_spec.rb @@ -246,7 +246,7 @@ expect(response).to eq({ status: :error, - message: "Devfile restrictions failed: No components present in devfile", + message: ["Devfile restrictions failed: No components present in devfile"], reason: :bad_request }) end diff --git a/lib/gitlab/fp/message_support.rb b/lib/gitlab/fp/message_support.rb index 8122d1a8ff5e74..9515ade1f36152 100644 --- a/lib/gitlab/fp/message_support.rb +++ b/lib/gitlab/fp/message_support.rb @@ -17,17 +17,17 @@ def self.extended(base) # @param [Symbol] reason # @return [Hash] def generate_error_response_from_message(message:, reason:) - details_string = + details = case message.content in {} nil - in { details: String => error_details } - error_details + in { details: String => error_detail } + error_detail in { details: Array => error_details } # NOTE: This join string intentionally has two spaces, so that it is a unique pattern which can be # split and parsed on the client if desired, to be presented in separate HTML elements. # We may eventually return an array of error messages, but this is a workaround for now. - error_details.join(", ") + error_details in { errors: ActiveModel::Errors => errors } errors.full_messages.join(", ") else @@ -35,7 +35,17 @@ def generate_error_response_from_message(message:, reason:) end # NOTE: Safe navigation operator is used here to prevent a type error, because Module#name is a 'String | nil' message_string = message.class.name&.demodulize&.underscore&.humanize - error_message = details_string ? "#{message_string}: #{details_string}" : message_string + + error_message = if details.is_a?(String) + details ? "#{message_string}: #{details}" : message_string + elsif details.is_a?(Array) + details.map do |error| + "#{message_string}: #{error}" + end + else + message_string + end + { status: :error, message: error_message, reason: reason } end end -- GitLab From 72c97dc185019d0d224049077ec3551f3e4c9b34 Mon Sep 17 00:00:00 2001 From: Omar Nasser Date: Sun, 24 Aug 2025 13:05:14 +0300 Subject: [PATCH 2/2] Add array as an accepted response type --- ee/app/services/remote_development/service_response_factory.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/app/services/remote_development/service_response_factory.rb b/ee/app/services/remote_development/service_response_factory.rb index 53b5fb9d564271..a9511acfb6b9aa 100644 --- a/ee/app/services/remote_development/service_response_factory.rb +++ b/ee/app/services/remote_development/service_response_factory.rb @@ -49,7 +49,7 @@ def validate_response_hash(response_hash) hash => { status: Symbol => status, payload: (Hash | NilClass) => payload, - message: (String | NilClass) => message, + message: (String | Array | NilClass) => message, reason: (Symbol | NilClass)=> reason, } -- GitLab