Skip to content

Commit de41dbb

Browse files
fix(output): additional bug fixes from second code review
- Fix E2E script: use --help instead of --version to detect TOON binary (tr --version outputs "tr 0.1.0" without "toon" string) - Fix Error() method: output errors in TOON format when TOON is requested instead of always using JSON - Fix error message: say "tru or tr binary" instead of just "tru" Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 62803d9 commit de41dbb

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

internal/output/output.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,18 @@ func (w *Writer) Success(msg string) {
116116

117117
// Error outputs an error message.
118118
func (w *Writer) Error(err error) {
119-
if w.format == FormatJSON || w.format == FormatTOON {
119+
payload := ErrorPayload{
120+
Error: "error",
121+
Message: err.Error(),
122+
Details: map[string]any{"code": 1},
123+
}
124+
if w.format == FormatJSON {
120125
_ = OutputJSONError(err, 1)
126+
} else if w.format == FormatTOON {
127+
// Use TOON encoding for error output
128+
_ = w.Write(payload)
121129
} else if w.format == FormatYAML {
122-
_ = OutputYAML(ErrorPayload{
123-
Error: "error",
124-
Message: err.Error(),
125-
Details: map[string]any{"code": 1},
126-
})
130+
_ = OutputYAML(payload)
127131
} else {
128132
fmt.Fprintf(w.errOut, "✗ %s\n", err.Error())
129133
}

internal/output/toon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func toonBinaryFromEnv() (string, error) {
120120
for _, env := range []string{"TOON_TRU_BIN", "TOON_BIN", "TRU_PATH"} {
121121
if val := strings.TrimSpace(os.Getenv(env)); val != "" {
122122
if !isToonRustBinary(val) {
123-
return "", fmt.Errorf("%s=%q does not appear to be toon_rust (expected tru)", env, val)
123+
return "", fmt.Errorf("%s=%q does not appear to be toon_rust (expected tru or tr binary)", env, val)
124124
}
125125
return val, nil
126126
}

scripts/test_toon_e2e.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ log " PASS: slb found at $(command -v slb)"
1717
# Note: Cargo.toml specifies "tru" but some builds produce "tr"
1818
if command -v tru >/dev/null 2>&1; then
1919
log " PASS: tru found at $(command -v tru)"
20-
elif command -v tr >/dev/null 2>&1 && tr --version 2>&1 | grep -qi "toon"; then
20+
elif command -v tr >/dev/null 2>&1 && tr --help 2>&1 | grep -qi "toon"; then
2121
log " PASS: tr (TOON) found at $(command -v tr)"
2222
elif [[ -x /data/projects/toon_rust/target/release/tru ]]; then
2323
log " PASS: tru found at /data/projects/toon_rust/target/release/tru"
@@ -69,7 +69,7 @@ toon_output=$(slb version --output toon 2>/dev/null)
6969
TRU_CMD=""
7070
if command -v tru >/dev/null 2>&1; then
7171
TRU_CMD="tru"
72-
elif command -v tr >/dev/null 2>&1 && tr --version 2>&1 | grep -qi "toon"; then
72+
elif command -v tr >/dev/null 2>&1 && tr --help 2>&1 | grep -qi "toon"; then
7373
TRU_CMD="tr"
7474
elif [[ -x /data/projects/toon_rust/target/release/tru ]]; then
7575
TRU_CMD="/data/projects/toon_rust/target/release/tru"

0 commit comments

Comments
 (0)