cli/cli · error · iostreams.BinaryTerminalError

%w; redirect or pipe stdout to save it, or pass --allow-esca

Error message

%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway

What it means

Error "%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway" thrown in cli/cli.

Source

Thrown at pkg/cmd/api/api.go:537

		}
	} else if isJSON && opts.IO.ColorEnabled() {
		err = jsoncolor.Write(bodyWriter, responseBody, ttyIndent)
	} else {
		if isJSON && opts.Paginate && !opts.Slurp && !isGraphQLPaginate && !opts.ShowResponseHeaders {
			responseBody = &paginatedArrayReader{
				Reader:      responseBody,
				isFirstPage: isFirstPage,
				isLastPage:  isLastPage,
			}
		}
		// A raw non-JSON body is the only response the transport does not sanitize.
		// It is faithful byte output, so binary bound for a terminal and text
		// carrying escape sequences are refused; the opt-out flag and discarded
		// output stream verbatim.
		if !isJSON && !opts.AllowEscapeSequences && bodyWriter != io.Discard {
			err = iostreams.CopyGuardedContent(bodyWriter, responseBody, opts.IO.IsStdoutTTY())
			if binErr, ok := errors.AsType[iostreams.BinaryTerminalError](err); ok {
				err = fmt.Errorf("%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway", binErr)
			} else if errors.Is(err, iostreams.ErrEscapeSequence) {
				err = errors.New("the response contains terminal escape sequences; pass --allow-escape-sequences to output it anyway")
			}
		} else {
			_, err = io.Copy(bodyWriter, responseBody)
		}
	}
	if err != nil {
		return
	}

	if serverError == "" && resp.StatusCode > 299 {
		serverError = fmt.Sprintf("HTTP %d", resp.StatusCode)
	}
	if serverError != "" {
		fmt.Fprintf(opts.IO.ErrOut, "gh: %s\n", serverError)
		if msg := api.ScopesSuggestion(resp); msg != "" {
			fmt.Fprintf(opts.IO.ErrOut, "gh: %s\n", msg)

View on GitHub (pinned to 0eeec0b92e)

Solutions

  1. Redirect stdout to a file, pipe it to another program, or pass --allow-escape-sequences to print the response anyway.

When it happens

Trigger: Thrown at pkg/cmd/api/api.go:537 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of cli/cli@0eeec0b92e (2026-08-15). Data as JSON: /api/errors/8f5b39a448f944e6. Report an issue: GitHub.