Skip to content

Commit dd1f09a

Browse files
committed
feat: extracting error message from the fastlane error
1 parent 076ad2b commit dd1f09a

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_android_app_action.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ def self.run(params)
6161
UI.success("Android build completed successfully!")
6262
result
6363
rescue StandardError => e
64-
UI.error("Android build failed: #{e.message}")
64+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
65+
UI.error("Android build failed: #{error_message}")
6566

6667
# Report build failure to Instabug
6768
Helper::InstabugStoresUploadHelper.report_status(
6869
branch_name:,
6970
api_key: instabug_api_key,
7071
status: "failure",
7172
step: "build_app",
72-
error_message: e.message
73+
error_message: error_message
7374
)
7475
raise e
7576
end

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_build_ios_app_action.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,16 @@ def self.run(params)
6161
UI.success("iOS build completed successfully!")
6262
result
6363
rescue StandardError => e
64-
UI.error("iOS build failed: #{e.message}")
64+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
65+
UI.error("iOS build failed: #{error_message}")
6566

6667
# Report build failure to Instabug
6768
Helper::InstabugStoresUploadHelper.report_status(
6869
branch_name:,
6970
api_key: instabug_api_key,
7071
status: "failure",
7172
step: "build_app",
72-
error_message: e.message
73+
error_message: error_message
7374
)
7475
raise e
7576
end

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_app_store_action.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def self.run(params)
4242
UI.success("App Store upload completed successfully!")
4343
result
4444
rescue StandardError => e
45-
UI.error("App Store upload failed: #{e.message}")
45+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
46+
47+
UI.error("App Store upload failed: #{error_message}")
4648

4749
# Report upload failure to Instabug
4850
Helper::InstabugStoresUploadHelper.report_status(

lib/fastlane/plugin/instabug_stores_upload/actions/instabug_upload_to_play_store_action.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def self.run(params)
4242
UI.success("Play Store upload completed successfully!")
4343
result
4444
rescue StandardError => e
45-
UI.error("Play Store upload failed: #{e.message}")
45+
error_message = Helper::InstabugStoresUploadHelper.extract_error_message(e.message)
46+
UI.error("Play Store upload failed: #{error_message}")
4647

4748
# Report upload failure to Instabug
4849
Helper::InstabugStoresUploadHelper.report_status(

lib/fastlane/plugin/instabug_stores_upload/helper/instabug_stores_upload_helper.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@ class InstabugStoresUploadHelper
1212
DEFAULT_INSTABUG_API_BASE_URL = "https://api.instabug.com".freeze
1313
INSTABUG_KEYS = %i[branch_name instabug_api_key instabug_api_base_url].freeze
1414

15+
# Extract the important part of an error message
16+
def self.extract_error_message(error_message)
17+
return error_message unless error_message.is_a?(String)
18+
19+
lines = error_message.split("\n")
20+
start_index = lines.find_index { |line| line.strip.start_with?("* What went wrong:") }
21+
end_index = lines.find_index { |line| line.strip.start_with?("* Try:") }
22+
23+
if start_index && end_index && end_index > start_index
24+
extracted_lines = lines[(start_index + 1)...end_index].map(&:strip).reject(&:empty?)
25+
return extracted_lines.join(" ")[0, 250] unless extracted_lines.empty?
26+
end
27+
28+
# Fallback message
29+
"Your build was triggered but failed during execution. " \
30+
"This could be due to missing environment variables or incorrect build credentials. " \
31+
"Check CI logs for full details."
32+
end
33+
1534
def self.show_message
1635
UI.message("Hello from the instabug_stores_upload plugin helper!")
1736
end

0 commit comments

Comments
 (0)