{"record":{"id":"8f5b39a448f944e6","repo":"cli/cli","slug":"w-redirect-or-pipe-stdout-to-save-it-or-pass","errorCode":null,"errorMessage":"%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway","messagePattern":"%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway","errorType":"console","errorClass":"iostreams.BinaryTerminalError","httpStatus":null,"severity":"error","filePath":"pkg/cmd/api/api.go","lineNumber":537,"sourceCode":"\t\t}\n\t} else if isJSON && opts.IO.ColorEnabled() {\n\t\terr = jsoncolor.Write(bodyWriter, responseBody, ttyIndent)\n\t} else {\n\t\tif isJSON && opts.Paginate && !opts.Slurp && !isGraphQLPaginate && !opts.ShowResponseHeaders {\n\t\t\tresponseBody = &paginatedArrayReader{\n\t\t\t\tReader:      responseBody,\n\t\t\t\tisFirstPage: isFirstPage,\n\t\t\t\tisLastPage:  isLastPage,\n\t\t\t}\n\t\t}\n\t\t// A raw non-JSON body is the only response the transport does not sanitize.\n\t\t// It is faithful byte output, so binary bound for a terminal and text\n\t\t// carrying escape sequences are refused; the opt-out flag and discarded\n\t\t// output stream verbatim.\n\t\tif !isJSON && !opts.AllowEscapeSequences && bodyWriter != io.Discard {\n\t\t\terr = iostreams.CopyGuardedContent(bodyWriter, responseBody, opts.IO.IsStdoutTTY())\n\t\t\tif binErr, ok := errors.AsType[iostreams.BinaryTerminalError](err); ok {\n\t\t\t\terr = fmt.Errorf(\"%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway\", binErr)\n\t\t\t} else if errors.Is(err, iostreams.ErrEscapeSequence) {\n\t\t\t\terr = errors.New(\"the response contains terminal escape sequences; pass --allow-escape-sequences to output it anyway\")\n\t\t\t}\n\t\t} else {\n\t\t\t_, err = io.Copy(bodyWriter, responseBody)\n\t\t}\n\t}\n\tif err != nil {\n\t\treturn\n\t}\n\n\tif serverError == \"\" && resp.StatusCode > 299 {\n\t\tserverError = fmt.Sprintf(\"HTTP %d\", resp.StatusCode)\n\t}\n\tif serverError != \"\" {\n\t\tfmt.Fprintf(opts.IO.ErrOut, \"gh: %s\\n\", serverError)\n\t\tif msg := api.ScopesSuggestion(resp); msg != \"\" {\n\t\t\tfmt.Fprintf(opts.IO.ErrOut, \"gh: %s\\n\", msg)","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/api/api.go#L519-L555","documentation":"Error \"%w; redirect or pipe stdout to save it, or pass --allow-escape-sequences to output it anyway\" thrown in cli/cli.","triggerScenarios":"Thrown at pkg/cmd/api/api.go:537 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Redirect stdout to a file, pipe it to another program, or pass --allow-escape-sequences to print the response anyway."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}