Skip to content

Commit 337ad45

Browse files
committed
Properly exit when requesting a build that does not exist
1 parent 3967be3 commit 337ad45

5 files changed

Lines changed: 16 additions & 3 deletions

File tree

bin/discord

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ bot.interaction_create do |event|
111111
SemanticLogger['DiscordBot'].info('Executing command', command: command)
112112
result = Pyxis::Cli.start(command, { debug: true })
113113
color = '#4caf50'
114+
rescue Pyxis::MessageError => e
115+
result = e.message
116+
color = '#f44336'
114117
rescue Thor::Error, Pyxis::Error => e
115118
result = "#{e.class}\n#{e.message}"
116119
color = '#f44336'

lib/pyxis.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
module Pyxis
99
Error = Class.new(StandardError)
10+
MessageError = Class.new(Pyxis::Error)
1011
end
1112

1213
loader = Zeitwerk::Loader.for_gem

lib/pyxis/commands/components.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Components < Thor
1010
def info
1111
component_versions = ManagedVersioning::ComponentInfo.new(options[:build]).execute
1212

13+
raise Pyxis::MessageError, 'This build does not exist' if component_versions.nil?
14+
1315
result = 'Versions of each component'
1416
component_versions.each do |component, version|
1517
result += "\n#{component}: #{version}"

lib/pyxis/gitlab_client.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,14 @@ def self.enhance_faraday(faraday)
4343
json = response.body.blank? ? nil : JSON.parse(response.body)
4444

4545
if json.is_a?(Hash)
46-
Thor::CoreExt::HashWithIndifferentAccess.new(json)
46+
Thor::CoreExt::HashWithIndifferentAccess.new(
47+
{
48+
body: Thor::CoreExt::HashWithIndifferentAccess.new(json),
49+
response: response,
50+
}
51+
)
4752
else
48-
json || response
53+
response
4954
end
5055
end
5156
end

lib/pyxis/managed_versioning/component_info.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def execute
1515
pipeline = GitlabClient.client.get_json(
1616
"/api/v4/projects/#{Project::Reticulum.api_gitlab_path}/pipelines/#{build_id}"
1717
)
18-
reticulum_sha = pipeline.sha
18+
return nil if pipeline.response.status == 404
19+
20+
reticulum_sha = pipeline.body.sha
1921

2022
components = {}
2123

0 commit comments

Comments
 (0)