Skip to content

Conversation

prkalle
Copy link
Contributor

@prkalle prkalle commented Oct 20, 2025

Description of the Change

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.

Users can provide the

 --output ./binary/file 

parameter as a workaround.

e.g:

❯ 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/[email protected]/util/panichandler/handler.go:19 +0x4b
	panic({0x51d35a0?, 0xc00080c090?})
		/Users/pkalle/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:783 +0x136
	text/template.Must(0xc00055c000?, {0x5466a68?, 0xc00080c090?})
		/Users/pkalle/go/pkg/mod/golang.org/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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})

Solution:

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.

Why Is This PR Valuable?

This PR would help users trying to download the binary data and trying to redirect the output using a pipe

Applicable Issues

List any applicable GitHub Issues here

How Urgent Is The Change?

Medium

@prkalle prkalle marked this pull request as ready for review October 20, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant