Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Wrangler shows ugly output for wrangler preview with workers that return binary data #218

Closed
xortive opened this issue Jun 5, 2019 · 8 comments
Labels
bug Something isn't working design feature Feature requests and suggestions

Comments

@xortive
Copy link
Contributor

xortive commented Jun 5, 2019

running wrangler preview outputs the result of a GET request to your worker to stdout. For workers that return binary data like images, this is rather ugly and fills your console with special characters, is this something that should be fixed?

@xtuc
Copy link
Member

xtuc commented Jun 6, 2019

I'm not sure how the preview works but we could check the Content-Type before showing it to the user.

@ashleygwilliams ashleygwilliams added bug Something isn't working feature Feature requests and suggestions design labels Jun 6, 2019
@ashleygwilliams
Copy link
Contributor

this is the type of thing that's right on the line of a bug and a feature! currently this is working as designed, it returns the exact thing the worker returns. this is not always useful tho! which means we should improve the design of this! i like the idea of the content-type, but i'm not sure that just removing things from the output is a good idea.

let's brainstorm in this thread!

@xtuc
Copy link
Member

xtuc commented Jun 6, 2019

but i'm not sure that just removing things from the output is a good idea.

Can you please clarify? We would remove the non printable responses.

@pwfff
Copy link

pwfff commented Jun 12, 2019

Piggy-backing on this instead of making a new issue:
It would be nice to provide options on how to render the output. In addition to content-type detection to not throw junk on the terminal, when I want to see the junk, I often want to pipe it to something else. This doesn't work that well currently though:

$ wrangler preview | xxd | head
00000000: e2ac 87ef b88f 2049 6e73 7461 6c6c 696e  ...... Installin
00000010: 6720 7761 736d 2d70 6163 6b2e 2e2e 0ae2  g wasm-pack.....
00000020: ac87 efb8 8f20 496e 7374 616c 6c69 6e67  ..... Installing
00000030: 2077 7261 6e67 6c65 726a 732e 2e2e 0ae2   wranglerjs.....
00000040: 9ca8 2020 2042 7569 6c74 2073 7563 6365  ..   Built succe
00000050: 7373 6675 6c6c 792e 0af0 9f91 b7e2 808d  ssfully.........
00000060: e299 80ef b88f 2047 4554 2068 7474 7073  ...... GET https
00000070: 3a2f 2f30 3030 3030 3030 3030 3030 3030  ://0000000000000
00000080: 3030 3030 3030 3030 3030 3030 3030 3030  0000000000000000
00000090: 3030 302e 636c 6f75 6466 6c61 7265 776f  000.cloudflarewo
000000a0: 726b 6572 732e 636f 6d0a f09f 91b7 e280  rkers.com.......
000000b0: 8de2 9980 efb8 8f20 596f 7572 2077 6f72  ....... Your wor
000000c0: 6b65 7220 7265 7370 6f6e 6465 6420 7769  ker responded wi
000000d0: 7468 3a20 efbf bd01 0102 001c 001c 0000  th: ............

I think my actual output starts after the 0x20, but I'm not sure 🤷‍♂

@gabbifish
Copy link
Contributor

It's been a while since this has last been picked up, and this is some good low-hanging fruit for us to take on! I still think we should absolutely provide an option for Wrangler to print ugly binary text to stdout, and I think it can be based on curl's approach:

$ curl https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Britishblue.jpg/800px-Britishblue.jpg
Warning: Binary output can mess up your terminal. Use "--output -" to tell curl to output it to your terminal anyway, or consider "--output <FILE>" to save to a file.

We can provide an error message like this and support identical flags. We can use the same heuristic as curl to determine whether a response is binary output or not: curl/curl@5385450

This also brings us to @pwfff's point: it would be really great to make the wrangler logging for preview optional. I suggest we add a silence flag to wrangler preview that allows folks to explicitly ask for Wrangler preview without helpful log messages (I say this instead of proposing a --verbose flag because I think the wrangler preview default messages are quite informative to first-time Wrangler users).

@gabbifish
Copy link
Contributor

Another thing we could do is make wrangler preview --headless also serve as our log-free version of wrangler preview (so it only returns the worker response, nothing else).

@ashleymichal
Copy link
Contributor

ashleymichal commented May 13, 2020

the stderr/stdout problem is its own thing (new issue created in #1283 ) but the rest of this issue was solved but wrangler dev is a better solution anyway.

@EverlastingBugstopper
Copy link
Contributor

i dont think --headless fixed this but wrangler dev should let you curl an endpoint and pipe to whatever you want so im fine closing this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working design feature Feature requests and suggestions
Projects
None yet
Development

No branches or pull requests

8 participants
@xortive @pwfff @ashleygwilliams @xtuc @ashleymichal @gabbifish @EverlastingBugstopper and others