Skip to content

Commit 642d71b

Browse files
committed
services/formula_wrapper: raise excpetion in initialize method
Signed-off-by: botantony <[email protected]>
1 parent b9279f2 commit 642d71b

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

Library/Homebrew/services/formula_wrapper.rb

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ def self.from(path_or_label)
3131
def initialize(formula)
3232
@formula = T.let(formula, Formula)
3333
@status_output_success_type = T.let(nil, T.nilable(StatusOutputSuccessType))
34+
35+
return if System.launchctl? || System.systemctl?
36+
37+
raise UsageError, System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
3438
end
3539

3640
# Delegate access to `formula.name`.
@@ -66,10 +70,8 @@ def service_name
6670
@service_name ||= T.let(
6771
if System.launchctl?
6872
formula.plist_name
69-
elsif System.systemctl?
73+
else # System.systemctl?
7074
formula.service_name
71-
else
72-
raise UsageError, System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
7375
end, T.nilable(String)
7476
)
7577
end
@@ -80,10 +82,8 @@ def service_file
8082
@service_file ||= T.let(
8183
if System.launchctl?
8284
formula.launchd_service_path
83-
elsif System.systemctl?
85+
else # System.systemctl?
8486
formula.systemd_service_path
85-
else
86-
raise UsageError, System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
8787
end, T.nilable(Pathname)
8888
)
8989
end
@@ -142,10 +142,8 @@ def loaded?(cached: false)
142142
if System.launchctl?
143143
reset_cache! unless cached
144144
status_success
145-
elsif System.systemctl?
145+
else # System.systemctl?
146146
System::Systemctl.quiet_run("status", service_file.basename)
147-
else
148-
raise UsageError, System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
149147
end
150148
end
151149

@@ -184,14 +182,15 @@ def owner
184182

185183
sig { returns(T::Boolean) }
186184
def pid?
187-
(p = pid).present? && p.positive?
185+
# (pid = self.pid).present? && pid.positive?
186+
(pid = self.pid).present? && pid.positive?
188187
end
189188

190189
sig { returns(T::Boolean) }
191190
def error?
192191
return false if pid?
193192

194-
(ec = exit_code).present? && !ec.zero?
193+
(exit_code = self.exit_code).present? && !exit_code.zero?
195194
end
196195

197196
sig { returns(T::Boolean) }
@@ -278,14 +277,12 @@ def status_output_success_type
278277
end
279278
odebug cmd.join(" "), output
280279
StatusOutputSuccessType.new(output, success, type)
281-
elsif System.systemctl?
280+
else # System.systemctl?
282281
cmd = ["status", service_name]
283282
output = System::Systemctl.popen_read(*cmd).chomp
284283
success = T.cast($CHILD_STATUS.present? && $CHILD_STATUS.success? && output.present?, T::Boolean)
285284
odebug [System::Systemctl.executable, System::Systemctl.scope, *cmd].join(" "), output
286285
StatusOutputSuccessType.new(output, success, :systemctl)
287-
else
288-
raise UsageError, System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
289286
end
290287
end
291288

@@ -310,7 +307,7 @@ def status_symbol
310307
:started
311308
elsif !loaded?(cached: true)
312309
:none
313-
elsif (ec = exit_code).present? && ec.zero?
310+
elsif (exit_code = self.exit_code).present? && exit_code.zero?
314311
if timed?
315312
:scheduled
316313
else

0 commit comments

Comments
 (0)