Skip to content

Commit 72a54b8

Browse files
committed
Fix eca_shell_command to include stderr output even when exit 0.
Fixes #265
1 parent b9f5584 commit 72a54b8

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix `eca_shell_command` to include stderr output even when exit 0.
6+
57
## 0.91.1
68

79
- Fix openai pro login exceptions related to graalvm.

src/eca/features/tools/shell.clj

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,16 @@
9393
(state-transition-fn :resources-destroyed {:resources (keys resources)}))))))
9494
err (some-> (:err result) string/trim)
9595
out (some-> (:out result) string/trim)]
96-
(cond
97-
(= result ::timeout)
96+
(if (= result ::timeout)
9897
(do
9998
(logger/debug logger-tag "Command timed out after " timeout " ms")
10099
(tools.util/single-text-content (str "Command timed out after " timeout " ms") true))
101-
102-
(zero? (:exit result))
103-
(do (logger/debug logger-tag "Command executed:" result)
104-
(tools.util/single-text-content (:out result)))
105-
106-
:else
107100
(do
108101
(logger/debug logger-tag "Command executed:" result)
109-
{:error true
102+
{:error (not (zero? (:exit result)))
110103
:contents (remove nil?
111104
(concat [{:type :text
112-
:text (str "Exit code " (:exit result))}]
105+
:text (str "Exit code: " (:exit result))}]
113106
(when-not (string/blank? err)
114107
[{:type :text
115108
:text (str "Stderr:\n" err)}])

test/eca/features/tools/shell_test.clj

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
(is (match?
2828
{:error true
2929
:contents [{:type :text
30-
:text "Exit code 1"}
30+
:text "Exit code: 1"}
3131
{:type :text
3232
:text "Stderr:\nSome error"}]}
3333
(with-redefs [fs/exists? (constantly true)
@@ -41,7 +41,11 @@
4141
(is (match?
4242
{:error false
4343
:contents [{:type :text
44-
:text "Some text"}]}
44+
:text "Exit code: 0"}
45+
{:type :text
46+
:text "Stderr:\nOther text"}
47+
{:type :text
48+
:text "Stdout:\nSome text"}]}
4549
(with-redefs [fs/exists? (constantly true)
4650
p/process (constantly (future {:exit 0 :out "Some text" :err "Other text"}))]
4751
((get-in f.tools.shell/definitions ["shell_command" :handler])
@@ -53,9 +57,11 @@
5357
(is (match?
5458
{:error false
5559
:contents [{:type :text
56-
:text "Some text"}]}
60+
:text "Exit code: 0"}
61+
{:type :text
62+
:text "Stdout:\nSome text"}]}
5763
(with-redefs [fs/exists? (constantly true)
58-
p/process (constantly (future {:exit 0 :out "Some text" :err "Other text"}))]
64+
p/process (constantly (future {:exit 0 :out "Some text"}))]
5965
((get-in f.tools.shell/definitions ["shell_command" :handler])
6066
{"command" "ls -lh"
6167
"working_directory" (h/file-path "/project/foo/src")}
@@ -86,9 +92,11 @@
8692
(is (match?
8793
{:error false
8894
:contents [{:type :text
89-
:text "also ok"}]}
95+
:text "Exit code: 0"}
96+
{:type :text
97+
:text "Stdout:\nalso ok"}]}
9098
(with-redefs [fs/exists? (constantly true)
91-
p/process (constantly (reset! proc (future {:exit 0 :err "ok" :out "also ok"})))]
99+
p/process (constantly (reset! proc (future {:exit 0 :out "also ok"})))]
92100
((get-in f.tools.shell/definitions ["shell_command" :handler])
93101
{"command" "ls -lh"}
94102
{:db {:workspace-folders [{:uri (h/file-uri "file:///project/foo") :name "foo"}]}
@@ -117,7 +125,9 @@
117125
(are [command] (match?
118126
{:error false
119127
:contents [{:type :text
120-
:text "Some output"}]}
128+
:text "Exit code: 0"}
129+
{:type :text
130+
:text "Stdout:\nSome output"}]}
121131
(with-redefs [fs/exists? (constantly true)
122132
p/process (constantly (future {:exit 0 :out "Some output"}))]
123133
((get-in f.tools.shell/definitions ["shell_command" :handler])

0 commit comments

Comments
 (0)