Skip to content

Commit 6088e5a

Browse files
committed
fix: make faaso CLI exit with error when server returns error
1 parent e5e8278 commit 6088e5a

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* A "local run" mode for debugging/development
88
* Make proxy start without explicit configuration
99
* Get rid of multirun
10-
* Propagate errors from `run_faaso` to the remote client
10+
* Propagate errors from `run_faaso` to the remote client
1111
* Setting up hostname for Caddy's automatic HTTPS
1212
* Config UI in frontend?
1313
* Add multi-container logs to web frontend. It's close but

config/faaso.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
password: adminfoo
33
scale:
44
builder: 0
5-
busqueda: 0
5+
busqueda: 2
66
foo: 0
77
fufu: 0
88
historico: 3

src/daemon/funko.cr

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ module Funko
121121

122122
post "/rpc/" do |env|
123123
args = env.params.json["args"].as(Array).map &.to_s
124-
run_faaso(args, env)
124+
begin
125+
run_faaso(args, env)
126+
rescue ex : Exception
127+
halt env, status_code: 500, response: "Error"
128+
end
125129
Config.reload
126130
Config.instance.save
127131
end
@@ -143,7 +147,9 @@ module Funko
143147
break if process.terminated?
144148
end
145149
end
146-
# FIXME: find a way to raise an exception on failure
147-
# of the faaso process
150+
# Because headers are already sent we need to send the
151+
# error condition in-band
152+
env.response.print("\n##--##--##--##ERROR") if $?.exit_code != 0
153+
env.response.flush
148154
end
149155
end

src/faaso.cr

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,21 @@ module Faaso
3232

3333
def self.rpc_call(args : Array(String)) : Int32
3434
user, password = Config.auth
35+
buf = IO::Memory.new
3536
Crest.post(
3637
"#{Config.server}rpc/",
3738
{"args" => args},
3839
user: user, password: password,
3940
json: true) do |response|
40-
IO.copy(response.body_io, STDOUT)
41+
IO.copy(response.body_io, buf)
42+
buf.seek(0)
43+
IO.copy(buf, STDOUT)
44+
end
45+
if buf.to_s.ends_with? "\n##--##--##--##ERROR"
46+
Log.error { "\nServer returned an error" }
47+
1
48+
else
49+
0
4150
end
42-
0
4351
end
4452
end

0 commit comments

Comments
 (0)