riscy / shx-for-emacs

An Emacs shell-mode (and comint-mode) extension that enables displaying small plots and graphics and lets users write shell commands in Emacs Lisp.
GNU General Public License v3.0
218 stars 10 forks source link

Can't display curl output #18

Closed ayrat555 closed 3 years ago

ayrat555 commented 4 years ago

It seems shx can not parse output from curl. The result is not displayed.

riscy commented 4 years ago

That's strange - can you paste the curl command and/or any messages that pop up? Did you change shx-triggers? Maybe you can M-x toggle-debug-on-error and try and see if it gives a traceback due to an error. It seems to be working at least in a simple couple simple cases:

~ $ curl https://api.github.com/repos/riscy
{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
}

~ $ curl https://api.github.com/repos/riscy/shx-for-emacs/issues
[
  {
    "url": "https://api.github.com/repos/riscy/shx-for-emacs/issues/18",
    "repository_url": "https://api.github.com/repos/riscy/shx-for-emacs",
    "labels_url": "https://api.github.com/repos/riscy/shx-for-emacs/issues/18/labels{/name}",
ayrat555 commented 4 years ago

Hi. Thanks for looking into the issue. Indeed, it works with your example. But it doesn't work with examples of mine.

shx-triggers is a variable defined in ‘shx.el’.                                                                      
Its value is                                                                                                         
(("https?://[A-Za-z0-9,./?=&;_-]+[^[:space:].\"'>)]+" . shx--parse-url))   

debug-on-error didn't show anything

My examples in shx:

➜  ~ curl -v -H "Content-Type: application/json" --data '{"1":"xyz","password":"xyz"}' http://localhost:4000/api/\
    v1/reorganize                                                                                                     
3012                                                                                                                  
3013<{"1":"xyz","password":"xyz"}' http://localhost:4000/api/v1/reorganize                                            
3014*   Trying 127.0.0.1...                                                                                           
3015* Connected to localhost (127.0.0.1) port 4000 (#0)                                                               
3016> POST /api/v1/reorganize HTTP/1.1                                                                                
3017> Host: localhost:4000                                                                                            
3018> User-Agent: curl/7.47.0                                                                                         
3019> Accept: */*                                                                                                     
3020> Content-Type: application/json                                                                                  
3021> Content-Length: 28                                                                                              
3022>                                                                                                                 
3023* upload completely sent off: 28 out of 28 bytes                                                                  
3024< HTTP/1.1 400 Bad Request                                                                                        
3025< cache-control: max-age=0, private, must-revalidate                                                              
3026< content-length: 115                                                                                             
3027< date: Sun, 08 Mar 2020 05:54:07 GMT                                                                             
3028< server: Cowboy                                                                                                  
3029< x-request-id: Ffo-atDXxTIXSm0AAABE                                                                              
3030<                                                                                                                 
3031* Connection #0 to host localhost left intact                                                                     
3032➜  ~           
3035➜  ~ curl -v -H "Content-Type: application/json" --data '{"0": [{"id": 10, "title": "House", "level": 0, "childre\
    n": [], "parent_id": null}], "1": [{"id": 12, "title": "Red Roof", "level": 1, "children": [], "parent_id": 10}, \
    {"id": 18, "title": "Blue Roof", "level": 1, "children": [], "parent_id": 10}, {"id": 13, "title": "Wall", "level\
    ": 1, "children": [], "parent_id": 10}], "2": [{"id": 17, "title": "Blue Window", "level": 2, "children": [], "pa\
    rent_id": 12}, {"id": 16, "title": "Door", "level": 2, "children": [], "parent_id": 13}, {"id": 15, "title": "Red\
     Window", "level": 2, "children": [], "parent_id": 12}]}' http://localhost:4000/api/v1/reorganize                 
3036<"Red Window", "level": 2, "children": [], "parent_id": 12}]}' http://localhost:4000/api/v1/reorganize            
    *   Trying 127.0.0.1...                                                                                           
    * Connected to localhost (127.0.0.1) port 4000 (#0)                                                               
    > POST /api/v1/reorganize HTTP/1.1                                                                                
    > Host: localhost:4000                                                                                            
    > User-Agent: curl/7.47.0                                                                                         
    > Accept: */*                                                                                                     
    > Content-Type: application/json                                                                                  
    > Content-Length: 564                                                                                             
    >                                                                                                                 
    * upload completely sent off: 564 out of 564 bytes                                                                
    < HTTP/1.1 200 OK                                                                                                 
    < cache-control: max-age=0, private, must-revalidate                                                              
    < content-length: 471                                                                                             
    < date: Sun, 08 Mar 2020 06:01:16 GMT                                                                             
    < server: Cowboy                                                                                                  
    < x-request-id: Ffo-zs0tPiNQnX0AAABk                                                                              
    <                                                                                                                 
    * Connection #0 to host localhost left intact                                                                     
    ➜  ~ ~ 

Examples in a regular terminal app:

➜  ~ curl -v -H "Content-Type: application/json" --data '{"1":"xyz","password":"xyz"}' http://localhost:4000/api/v1/reorganize
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4000 (#0)
> POST /api/v1/reorganize HTTP/1.1
> Host: localhost:4000
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 28
> 
* upload completely sent off: 28 out of 28 bytes
< HTTP/1.1 400 Bad Request
< cache-control: max-age=0, private, must-revalidate
< content-length: 115
< date: Sun, 08 Mar 2020 06:02:32 GMT
< server: Cowboy
< x-request-id: Ffo-4LsGiyu3k_sAAACE
< 
* Connection #0 to host localhost left intact
{"#/1":"Type mismatch. Expected Array but got String.","#/password":"Schema does not allow additional properties."}% 
➜  ~ curl -v -H "Content-Type: application/json" --data '{"0": [{"id": 10, "title": "House", "level": 0, "children": [], "parent_id": null}], "1": [{"id": 12, "title": "Red Roof", "level": 1, "children": [], "parent_id": 10}, {"id": 18, "title": "Blue Roof", "level": 1, "children": [], "parent_id": 10}, {"id": 13, "title": "Wall", "level": 1, "children": [], "parent_id": 10}], "2": [{"id": 17, "title": "Blue Window", "level": 2, "children": [], "parent_id": 12}, {"id": 16, "title": "Door", "level": 2, "children": [], "parent_id": 13}, {"id": 15, "title": "Red Window", "level": 2, "children": [], "parent_id": 12}]}' http://localhost:4000/api/v1/reorganize
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 4000 (#0)
> POST /api/v1/reorganize HTTP/1.1
> Host: localhost:4000
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 564
> 
* upload completely sent off: 564 out of 564 bytes
< HTTP/1.1 200 OK
< cache-control: max-age=0, private, must-revalidate
< content-length: 471
< date: Sun, 08 Mar 2020 06:03:06 GMT
< server: Cowboy
< x-request-id: Ffo-6Jv9Px6ipOkAAACk
< 
* Connection #0 to host localhost left intact
[{"children":[{"children":[],"id":18,"level":1,"parent_id":10,"title":"Blue Roof"},{"children":[{"children":[],"id":16,"level":2,"parent_id":13,"title":"Door"}],"id":13,"level":1,"parent_id":10,"title":"Wall"},{"children":[{"children":[],"id":17,"level":2,"parent_id":12,"title":"Blue Window"},{"children":[],"id":15,"level":2,"parent_id":12,"title":"Red Window"}],"id":12,"level":1,"parent_id":10,"title":"Red Roof"}],"id":10,"level":0,"parent_id":null,"title":"House"}]%
ayrat555 commented 4 years ago

Can this be caused to the fact that I'm making requests to localhost?

riscy commented 4 years ago

I don't think that should have anything to do with it. One thing you could do is disable shx-mode (M-x shx-mode) to ensure that the issue isn't with the built-in Emacs shell.

Even if it is something to do with the built-in Emacs shell, we can still try to diagnose it here. Another thing you could check is the output of command -v curl in both environments, as it's possible you might be running different versions of curl between the two?

riscy commented 3 years ago

I'll close this for now, but feel free to reopen if you find out that it was shx doing it. :)