Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A route with an empty argument throws an error "Can't read from an empty string" #9

Closed
vindarel opened this issue Jan 10, 2018 · 1 comment
Labels

Comments

@vindarel
Copy link

I had this route, checking if its parameter is void:

(defroute torrents (:get :text/html &key query)
          ;; now fails if no query. How do we do ?
          (if query
              (print-results (torrents:async-torrents query) query)
              (redirect-to "index")))

it worked (mmh… can't be 100% sure now), but now I get an exception from this fix when I explicitly go to an url like torrents&query=, with a trailing =. The routes torrents&query (no =) or torrents do not throw a condition and do redirect to my index.

#<ERROR-WHEN-EXPLAINING #<UNCONVERTIBLE-ARGUMENT 400: Malformed arg for resource TORRENTS>> Here's a little bit more information: 
You got a #<ERROR-WHEN-EXPLAINING 
#<UNCONVERTIBLE-ARGUMENT 400: Malformed arg for resource TORRENTS>> because: 
SNOOZE:EXPLAIN-CONDITION was trying to explain to the user the condition #<UNCONVERTIBLE-ARGUMENT 400: Malformed arg for resource TORRENTS>. You got a #<UNCONVERTIBLE-ARGUMENT 400: Malformed arg for resource TORRENTS> because: 
SNOOZE:URI-TO-ARGUMENTS was trying to make sense of 
the key-value-pair "query" and "" when it caught #<SNOOZE-READER-ERROR Can't read from an empty string> 

No more interesting information on #<SNOOZE-READER-ERROR 
Can't read from an empty string>, sorry

I highlight:

SNOOZE:URI-TO-ARGUMENTS was trying to make sense of the key-value-pair "query" and "" when it caught #<SNOOZE-READER-ERROR Can't read from an empty string>

Maybe can Snooze better handle empty strings ?

@joaotavora
Copy link
Owner

joaotavora commented Jan 18, 2018

I forgot to answer this a week ago.

Look, this isn't really a bug, it's just the way snooze works. Any HTTP client might call your route with an empty string to the "query" argument. The only way to do so is to use a malformed URL and the answer from the server must be a "400: Malformed" HTTP code.

So Snooze issues that error internally as a Lisp condition, and that's OK. Now, if you want to present a pretty webpage explaining the error you should write a suitable SNOOZE:EXPLAIN-CONDITIONmethod. The same if you want to provide a suitable JSON response. If you don't have any of these methods, SNOOZE will do the following:

  • If you have SNOOZE:*CATCH-ERRORS* set to :verbose (as you do in this example, keeping in mind that it is something that shouldn't be in a production server), you get this message to remind you that you should write a SNOOZE:EXPLAIN-CONDITION method.
  • If you have SNOOZE:*CATCH-ERRORS* set to t (the default), you get a very terse text response.

I'm assigning this a "question" label and adding a WIKI entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants