V8: Fix(cf curl): Prevent errors when handling binary API responses by prkalle · Pull Request #3605 · cloudfoundry/cli
Problem:
When cf cli receives binary data from the API, such as when downloading a droplet with the command
cf curl /v3/droplets/48155813-038b-4fbd-912d-7f8856c39f9c/download > /tmp/droplet
it crashes while trying to process the binary data.
parameter as a workaround.
❯ cf curl /v3/droplets/42c4ddb3-9d3e-4cce-a818-27bdb68876d2/download > /tmp/droplet
Something unexpected happened. This is a bug in cf.
Please re-run the command that caused this exception with the environment
variable CF_TRACE set to true.
Also, please update to the latest cli and try the command again:
https://code.cloudfoundry.org/cli/releases
Please create an issue at: https://code.cloudfoundry.org/cli/issues
Include the below information when creating the issue:
Command
cf curl /v3/droplets/42c4ddb3-9d3e-4cce-a818-27bdb68876d2/download
CLI Version
99.0.0-dev-7b6f41e+build1061000
Error
template: Display Text:656: unrecognized character in action: U+FFFD '�'
Stack Trace
goroutine 1 [running]:
code.cloudfoundry.org/cli/util/panichandler.HandlePanic()
/Users/pkalle/go/pkg/mod/code.cloudfoundry.org/cli@v0.0.0-20250924014223-4a50d59e60cf/util/panichandler/handler.go:19 +0x4b
panic({0x51d35a0?, 0xc00080c090?})
/Users/pkalle/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-amd64/src/runtime/panic.go:783 +0x136
text/template.Must(0xc00055c000?, {0x5466a68?, 0xc00080c090?})
/Users/pkalle/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-amd64/src/text/template/helper.go:26 +0x2f
code.cloudfoundry.org/cli/util/ui.generateTranslationFunc.func1({0xc000a82000, 0x68c8e0}, {0xc00080c020, 0x1, 0x3fe9295?})
/Users/pkalle/go/pkg/mod/code.cloudfoundry.org/cli@v0.0.0-20250924014223-4a50d59e60cf/util/ui/i18n.go:119 +0xde
code.cloudfoundry.org/cli/util/ui.(*UI).TranslateText(0xc0001bab00, {0xc000a82000, 0x68c8e0}, {0x0?, 0x0?, 0x3f7d500?})
/Users/pkalle/go/pkg/mod/code.cloudfoundry.org/cli@v0.0.0-20250924014223-4a50d59e60cf/util/ui/ui.go:406 +0x95
code.cloudfoundry.org/cli/util/ui.(*UI).DisplayText(0xc0001bab00, {0xc000a82000, 0x68c8e0}, {0x0, 0x0, 0x0})
/Users/pkalle/go/pkg/mod/code.cloudfoundry.org/cli@v0.0.0-20250924014223-4a50d59e60cf/util/ui/ui.go:248 +0xaa
code.cloudfoundry.org/cli/command/v7.CurlCommand.Execute({{{0x5490fd0, 0xc0001bab00}, {0x54947a0, 0xc000634400}, {0x547ea48, 0xc000612560}, {0x549b880, 0xc0006f8a10}, 0xc000774f08, 0xc0005e2720}, ...}, ...)
/Users/pkalle/go/pkg/mod/code.cloudfoundry.org/cli@v0.0.0-20250924014223-4a50d59e60cf/command/v7/curl_command.go:58 +0x29a
github.gwd.broadcom.net/TNZ/tanzu-cf-cli-runtime/command_parser.(*CommandParser).getExecutionWrapper.func1({0x4e471480, 0x5fd94d0}, {0xc000612400, 0x0, 0x2})
The fix is to detect when the response contains binary data and by writing the raw bytes directly to stdout instead of converting to string, we avoid data corruption.
This PR would help users trying to download the binary data and trying to redirect the output using a pipe