On Mar 3, 7:38 am, Jonathan Lundell <[email protected]> wrote:
> On Mar 3, 2011, at 1:46 AM, darkblue_b wrote:

>
> >>> @jonathan: Yes, a more detailed error messages than "no json" would be 
> >>> awesome.
>
> >> generic.json now says:
>
> >> {{
> >> ###
> >> # response._vars contains the dictionary returned by the controller action
> >> ###
> >> try:
> >>    from gluon.serializers import json
> >>    response.write(json(response._vars),escape=False)
> >>    response.headers['Content-Type']='text/json'
> >> except:
> >>    raise HTTP(405,'no json')
>
> >> }}
>
> >> I suggest this instead:
>
> >> {{
> >> ###
> >> # response._vars contains the dictionary returned by the controller action
> >> ###
> >> try:
> >>         from gluon.serializers import json
> >>         response.write(json(response._vars), escape=False)
> >>         response.headers['Content-Type'] = 'application/json'
> >> except (TypeError, ValueError):
> >>         raise HTTP(405, 'JSON serialization error')
> >> except ImportError:
> >>         raise HTTP(405, 'JSON not available')
> >> except:
> >>         raise HTTP(405, 'JSON error')
>
> >> }}
>
> > I patched that in, and changed the last one to say
>
> > except Exception, E:
> >    raise HTTP(405, 'JSON error: ' + str(E))
>
> > and got in my case
> >   JSON error: 'id'
>
> Ah. Let's find out a little more. I suggest two experiments.
>
> The easier one: include E.__class__.__name__ in the string, so we can see 
> what's being raised.
>
> Then I'd like to see if we can force a ticket. Try changing the last raise 
> to: raise SyntaxError, and if you get a stack trace, let's see where the 
> exception is coming from.
>
> When I took a look through the code, it looked to me like serialization 
> errors were all causing Type or Value exceptions, but I might have missed 
> something.

ok, in order
  E.__class__.__name__  => KeyError

then, substituting SyntaxError does indeed create a stack trace
  File "..../web2py/gluon/restricted.py", line 188, in restricted
    exec ccode in environment
  File  (the view I am testing)
    SyntaxError: None


Reply via email to