Module: Mysigner::CLI::Concerns::ErrorHandlers

Included in:
Mysigner::CLI
Defined in:
lib/mysigner/cli/concerns/error_handlers.rb

Instance Method Summary collapse

Instance Method Details

#handle_android_api_error(error, context: {}) ⇒ Object

Handle Google Play API errors with actionable suggestions



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 180

def handle_android_api_error(error, context: {})
  error_message = error.message.to_s

  say ''
  say '=' * 80, :red
  say "#{context[:title] || 'Google Play API Error'}", :red
  say '=' * 80, :red
  say ''
  say "Error: #{error_message}", :red
  say ''

  if error.respond_to?(:suggestion) && error.suggestion
    say "Suggestion: #{error.suggestion}", :yellow
    say ''
  end

  # Check for specific Google Play error patterns
  if error_message =~ /keystore.*not.*found|no.*keystore|missing.*keystore/i
    show_keystore_not_found_suggestions
  elsif error_message =~ /keystore.*password|wrong.*password/i
    show_keystore_password_suggestions
  elsif error_message =~ /package.*not.*found|first.*build.*uploaded.*manually/i
    show_first_upload_suggestions(context[:package_name])
  elsif error_message =~ /version.*code.*already|already.*used/i
    show_version_code_conflict_suggestions
  elsif error_message =~ /service.*account.*not.*found|no.*credentials/i
    
  elsif error_message =~ /not.*authorized|permission.*denied|forbidden/i
    show_permission_denied_suggestions
  elsif error_message =~ /precondition.*failed|track.*not.*ready/i
    show_track_not_setup_suggestions(context[:track])
  elsif error_message =~ /aab.*not.*found|no.*aab.*file/i
    show_aab_not_found_suggestions
  elsif show_actionable_suggestions(error, platform: :android)
    # Suggestions already shown
  else
    show_generic_android_suggestions
  end

  show_saved_files(context)
  show_debug_info(error)
end

#handle_apple_api_error(error, context: {}) ⇒ Object

Handle Apple API errors with actionable suggestions



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 134

def handle_apple_api_error(error, context: {})
  error_message = error.message.to_s

  say ''
  say '=' * 80, :red
  say "#{context[:title] || 'Apple API Error'}", :red
  say '=' * 80, :red
  say ''
  say "Error: #{error_message}", :red
  say ''

  if error.respond_to?(:suggestion) && error.suggestion
    say "Suggestion: #{error.suggestion}", :yellow
    say ''
  end

  # Check for specific Apple error patterns
  if error_message =~ /no.*build.*found|build.*not.*found|no.*processed.*build/i
    show_build_not_found_suggestions(context)
  elsif error_message =~ /still.*processing|processing.*build/i
    show_build_processing_suggestions
  elsif error_message =~ /profile.*expired|provisioning.*expired|certificate.*expired/i
    show_expired_credential_suggestions
  elsif error_message =~ /profile.*not.*found|no.*provisioning.*profile|missing.*profile/i
    show_profile_not_found_suggestions
  elsif error_message =~ /certificate.*not.*found|no.*signing.*certificate/i
    show_certificate_not_found_suggestions
  elsif error_message =~ /app.*with.*bundle.*id.*not.*found|app.*not.*found/i
    show_app_not_found_suggestions(context[:bundle_id])
  elsif error_message =~ /missing.*required.*field|what's.*new.*required|cannot.*submit.*missing/i
    
  elsif error_message =~ /archive.*not.*found|no.*xcarchive/i
    show_archive_not_found_suggestions
  elsif error_message =~ /ipa.*not.*found|no.*ipa.*file/i
    show_ipa_not_found_suggestions
  elsif show_actionable_suggestions(error, platform: :ios)
    # Suggestions already shown
  else
    show_generic_apple_suggestions
  end

  show_saved_files(context)
  show_debug_info(error)
end

#handle_connection_error(error, api_url) ⇒ Object

Handle connection error



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 71

def handle_connection_error(error, api_url)
  say ''
  say '=' * 80, :red
  say '✗ Connection Failed', :red
  say '=' * 80, :red
  say ''
  say "Error: #{error.message}", :red
  say ''
  say 'Possible causes:', :yellow
  say "  • My Signer API is not running at #{api_url}"
  say '  • Network connectivity issues'
  say '  • Firewall blocking the connection'
  say '  • Incorrect API URL'
  say ''
  say 'To fix this:', :cyan
  say ''
  if api_url.include?('localhost')
    say '  For local development:', :bold
    say '    1. Make sure Rails server is running:'
    say '       cd path/to/my-signer'
    say '       bin/rails server'
    say ''
    say "    2. Verify it's accessible:"
    say "       curl #{api_url}/up"
  else
    say '  For production:', :bold
    say '    1. Check the API URL is correct'
    say '    2. Verify the service is running'
    say '    3. Check your internet connection'
  end
  say ''
  say '  Or set a custom API URL:', :bold
  say '    export MYSIGNER_API_URL=http://your-server.com'
  say ''
  say "💡 Run 'mysigner onboard' to reconfigure", :yellow
  say ''
end

#handle_connection_failure(api_url) ⇒ Object

Handle connection failure



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 20

def handle_connection_failure(api_url)
  say ''
  say 'Possible issues:', :yellow
  say "  • API server is not running at #{api_url}"
  say '  • Network connectivity problems'
  say '  • Incorrect API URL'
  say ''
  say '💡 Try:', :cyan
  say '  • Check the API URL is correct'
  say '  • Verify the server is running'
  say "  • Run 'mysigner onboard' for guided setup"
end

#handle_unauthorized_error(api_url) ⇒ Object

Handle unauthorized error



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 45

def handle_unauthorized_error(api_url)
  say ''
  say '=' * 80, :red
  say '✗ Authentication Failed', :red
  say '=' * 80, :red
  say ''
  say 'Your API token is invalid or has been revoked.', :bold
  say ''
  say 'Common reasons:', :yellow
  say '  • Token was copied incorrectly (missing characters)'
  say '  • Token was revoked in the web dashboard'
  say '  • Token has expired'
  say "  • You're using the wrong API URL"
  say ''
  say 'To fix this:', :cyan
  say "  1. Go to: #{api_url}/organizations/YOUR_ORG/api_tokens"
  say '  2. Check if your token is still active'
  say '  3. If revoked or expired, create a new token'
  say '  4. Copy the NEW token carefully (entire string)'
  say "  5. Run 'mysigner login' again"
  say ''
  say "💡 Or run 'mysigner onboard' for guided setup", :yellow
  say ''
end

#handle_unexpected_error(error, api_url) ⇒ Object

Handle unexpected error



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 110

def handle_unexpected_error(error, api_url)
  say ''
  say '=' * 80, :red
  say '✗ Unexpected Error', :red
  say '=' * 80, :red
  say ''
  say "Error: #{error.message}", :red
  say "Type: #{error.class}", :red if ENV['DEBUG']
  say ''
  say 'This is unexpected. Please try:', :yellow
  say "  1. Run 'mysigner onboard' to reconfigure"
  say "  2. Check #{api_url} is accessible"
  say "  3. Run 'mysigner doctor' to check your environment"
  say ''
  if ENV['DEBUG']
    say 'Stack trace:', :red
    say error.backtrace.first(5).join("\n"), :red
  else
    say '💡 For more details, run with DEBUG=1', :yellow
  end
  say ''
end

#show_create_org_guidance(api_url) ⇒ Object

Show guidance for creating an organization



34
35
36
37
38
39
40
41
42
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 34

def show_create_org_guidance(api_url)
  say 'To create an organization:', :cyan
  say "  1. Go to: #{api_url}"
  say '  2. Sign in to your account'
  say "  3. Click 'Create Organization'"
  say '  4. Then generate a new API token for that organization'
  say ''
  say "💡 Run 'mysigner onboard' for step-by-step guidance", :yellow
end

#show_token_guidance(api_url) ⇒ Object

Show guidance for getting a token



8
9
10
11
12
13
14
15
16
17
# File 'lib/mysigner/cli/concerns/error_handlers.rb', line 8

def show_token_guidance(api_url)
  say "Don't have a token yet?", :yellow
  say "  1. Go to: #{api_url}", :cyan
  say '  2. Navigate to: Your Organization → API Tokens', :cyan
  say "  3. Click 'Create Token'", :cyan
  say "  4. Copy the token (you'll only see it once!)", :cyan
  say ''
  say "💡 Or run 'mysigner onboard' for step-by-step guidance", :yellow
  say ''
end