On Wednesday 22 July 2009 12:18:52 mdipierro wrote:
> Some of them have been fixed but some may still need fixes. Help will
> be appreciated.
Ok, here it is.
I went over all files in gluon/ and changed all raises that were providing
uhelpful (IMHO of course) tracebacks.
Patch is against current trunk
> Massimo
>
> On Jul 22, 3:09 am, Alexey Nezhdanov <[email protected]> wrote:
> > On Friday 17 July 2009 19:11:11 JohnMc wrote:> BTW, this is perfect
> > example of helpless backtrace.
> >
> > > Consider how much better it would be if it look like this:
> > > ==============
> > > SyntaxError: invalid field name: 'tablename.fieldname'
> > >
> > > -- Alexey
> > >
> > > That might have helped some. But to tell you the truth I went field by
> > > field twice looking for just such an occurrence.
> >
> > EXACTLY! You were looking for an error looking _field_by_field_. Even if
> > you have just 50 of them - that's a lot of work. Instead of concentrating
> > on the SINGLE field.> My own mind filled in
> >
> > > the blank. That level of human error no amount of syntax checking will
> > > solve.
> >
> > I'm sure it can be helped. Human errors are well known and backtraces are
> > the perfect place to help fixing them.
> >
> > Anyways, Massimo - I didn't look into the code for a while already so I
> > do not know how the things are at the moment. Do you want me to go over
> > all 'raise' statements and submit a patch that will add more useful info
> > just like in this example?
> >
> > > Just sayin'.
> > >
> > > On Jul 17, 2:12 am, Alexey Nezhdanov <[email protected]> wrote:
> > > > BTW, this is perfect example of helpless backtrace.
> > > > Consider how much better it would be if it look like this:
> > > > ==============
> > > > SyntaxError: invalid field name: 'tablename.fieldname'
> > > > ==============
> > > >
> > > > I submitted couple of similar patches some time ago, do not know if
> > > > they were
> > > > included:http://groups.google.com/group/web2py/browse_thread/thread/8
> > > >568a 5ea58...
> > > >
> > > > --
> > > > Sincerely yours
> > > > Alexey Nezhdanov
> >
> > --
> > Sincerely yours
> > Alexey Nezhdanov
>
>
--
Sincerely yours
Alexey Nezhdanov
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---
=== modified file 'gluon/contrib/feedparser.py'
--- gluon/contrib/feedparser.py 2009-05-15 16:51:05 +0000
+++ gluon/contrib/feedparser.py 2009-07-23 06:45:03 +0000
@@ -3268,7 +3268,7 @@
if _debug:
sys.stderr.write('date handler function must return 9-tuple\n'
)
- raise ValueError
+ raise ValueError('date handler function must return 9-tuple')
map(int, date9tuple)
return date9tuple
except Exception, e:
=== modified file 'gluon/contrib/gql.py'
--- gluon/contrib/gql.py 2009-07-18 02:52:22 +0000
+++ gluon/contrib/gql.py 2009-07-23 06:49:18 +0000
@@ -193,7 +193,7 @@
elif isinstance(field, SQLTable):
new_fields += [copy.copy(field[f]) for f in field.fields if f != 'id']
else:
- raise SyntaxError, 'define_table argument is not a SQLField'
+ raise SyntaxError, 'define_table argument \'%s\'is not a SQLField'%field
fields = new_fields
self._db = db
self._tablename = tablename
@@ -594,7 +594,7 @@
def __call__(self, where):
if isinstance(self.where, QueryException) or isinstance(where,
QueryException):
- raise SyntaxError
+ raise SyntaxError("Neither self.where nor where can't be a QueryException instance")
if self.where:
return SQLSet(self._db, self.where & where)
else:
=== modified file 'gluon/contrib/memdb.py'
--- gluon/contrib/memdb.py 2009-07-18 02:52:22 +0000
+++ gluon/contrib/memdb.py 2009-07-23 07:35:42 +0000
@@ -50,7 +50,7 @@
def cleanup(text):
if re.compile('[^0-9a-zA-Z_]').findall(text):
raise SyntaxError, \
- 'only [0-9a-zA-Z_] allowed in table and field names'
+ 'Can\'t cleanup \'%s\': only [0-9a-zA-Z_] allowed in table and field names' % text
return text
@@ -114,7 +114,7 @@
def __setattr__(self, key, value):
if key in self:
- raise SyntaxError, 'Object exists and cannot be redefined'
+ raise SyntaxError, 'Object \'%s\'exists and cannot be redefined' % key
self[key] = value
def __repr__(self):
@@ -154,11 +154,11 @@
):
tablename = cleanup(tablename)
if tablename in dir(self) or tablename[0] == '_':
- raise SyntaxError, 'invalid table name'
+ raise SyntaxError, 'invalid table name: %s' % tablename
if not tablename in self.tables:
self.tables.append(tablename)
else:
- raise SyntaxError, 'table already defined'
+ raise SyntaxError, 'table already defined: %s' % tablename
t = self[tablename] = SQLTable(self, tablename, *fields)
t._create()
return t
@@ -219,21 +219,24 @@
if field.type[:9] == 'reference':
referenced = field.type[10:].strip()
if not referenced:
- raise SyntaxError, 'SQLTable: reference to nothing!'
+ raise SyntaxError, \
+ 'SQLTable %s: reference \'%s\' to nothing!' % (self._tablename, k)
if not referenced in self._db:
- raise SyntaxError, 'SQLTable: table does not exist'
+ raise SyntaxError, \
+ 'SQLTable: table %s does not exist' % referenced
referee = self._db[referenced]
ftype = \
self._db._translator[field.type[:9]](
self._db[referenced]._tableobj)
if self._tablename in referee.fields: # ## THIS IS OK
raise SyntaxError, \
- 'SQLField: table name has same name as a field in referenced table'
+ 'SQLField: table \'%s\' has same name as a field ' \
+ 'in referenced table \'%s\'' % (self._tablename, referenced)
self._db[referenced]._referenced_by.append((self._tablename,
field.name))
elif not field.type in self._db._translator\
or not self._db._translator[field.type]:
- raise SyntaxError, 'SQLField: unkown field type'
+ raise SyntaxError, 'SQLField: unkown field type %s' % field.type
self._tableobj = self._db.client
return None
@@ -394,7 +397,7 @@
self.name = cleanup(fieldname)
if fieldname in dir(SQLTable) or fieldname[0] == '_':
- raise SyntaxError, 'SQLField: invalid field name'
+ raise SyntaxError, 'SQLField: invalid field name: %s' % fieldname
if isinstance(type, SQLTable):
type = 'reference ' + type._tablename
if not length and type == 'string':
@@ -508,7 +511,7 @@
id=long(right))
return
else:
- raise SyntaxError, 'not supported'
+ raise SyntaxError, 'only equality by id is supported'
raise SyntaxError, 'not supported'
def __str__(self):
@@ -555,7 +558,8 @@
def __call__(self, where):
if isinstance(self.where, QueryException) or isinstance(where,
QueryException):
- raise SyntaxError
+ raise SyntaxError, \
+ 'neither self.where nor where can be a QueryException instance'
if self.where:
return SQLSet(self._db, self.where & where)
else:
@@ -609,7 +613,7 @@
return
self._db[tablename].delete(id)
else:
- raise Exception, 'not implemented'
+ raise Exception, 'deletion not implemented'
def update(self, **update_fields):
if isinstance(self.where, QueryException):
@@ -620,7 +624,7 @@
setattr(item, key, value)
self._db[tablename].update(id, **item)
else:
- raise Exception, 'not implemented'
+ raise Exception, 'update not implemented'
def update_record(
@@ -660,7 +664,7 @@
def __getitem__(self, i):
if i >= len(self.response) or i < 0:
- raise SyntaxError, 'SQLRows: no such row'
+ raise SyntaxError, 'SQLRows: no such row: %i' % i
if len(self.response[0]) != len(self.colnames):
raise SyntaxError, 'SQLRows: internal error'
row = SQLStorage()
=== modified file 'gluon/contrib/rss2.py'
--- gluon/contrib/rss2.py 2009-07-18 02:52:22 +0000
+++ gluon/contrib/rss2.py 2009-07-23 07:04:44 +0000
@@ -514,7 +514,7 @@
if title is None and description is None:
raise TypeError(
- "must define at least one of 'title' or 'description'")
+ "RSSItem must define at least one of 'title' or 'description'")
self.title = title
self.link = link
self.description = description
=== modified file 'gluon/contrib/simplejson/encoder.py'
--- gluon/contrib/simplejson/encoder.py 2009-05-25 03:54:40 +0000
+++ gluon/contrib/simplejson/encoder.py 2009-07-23 07:07:39 +0000
@@ -293,7 +293,7 @@
if markers is not None:
markerid = id(lst)
if markerid in markers:
- raise ValueError("Circular reference detected")
+ raise ValueError("Circular reference detected: %s" % markerid)
markers[markerid] = lst
buf = '['
if _indent is not None:
@@ -346,7 +346,7 @@
if markers is not None:
markerid = id(dct)
if markerid in markers:
- raise ValueError("Circular reference detected")
+ raise ValueError("Circular reference detected: %s" % markerid)
markers[markerid] = dct
yield '{'
if _indent is not None:
@@ -439,7 +439,7 @@
if markers is not None:
markerid = id(o)
if markerid in markers:
- raise ValueError("Circular reference detected")
+ raise ValueError("Circular reference detected: %s" % markerid)
markers[markerid] = o
o = _default(o)
for chunk in _iterencode(o, _current_indent_level):
=== modified file 'gluon/contrib/spreadsheet.py'
--- gluon/contrib/spreadsheet.py 2009-07-18 02:52:22 +0000
+++ gluon/contrib/spreadsheet.py 2009-07-23 07:07:58 +0000
@@ -139,7 +139,7 @@
"""
key = str(key)
if not self.regex.match(key):
- raise SyntaxError, "Invalid cell name"
+ raise SyntaxError, "Invalid cell name: %s" % key
node = Node(key, value, self.url, readonly, active, onchange)
self.nodes[key] = node
self[key] = value
=== modified file 'gluon/globals.py'
--- gluon/globals.py 2009-07-18 02:52:22 +0000
+++ gluon/globals.py 2009-07-23 07:10:02 +0000
@@ -111,7 +111,7 @@
def render(self, *a, **b):
if len(a) > 2:
- raise SyntaxError
+ raise SyntaxError('Response.render can be called with two arguments, at most')
elif len(a) == 2:
(view, self._vars) = (a[0], a[1])
elif len(a) == 1 and isinstance(a[0], str):
@@ -298,7 +298,7 @@
key = request.cookies[response.session_id_name].value
(record_id, unique_key) = key.split(':')
if record_id == '0':
- raise Exception
+ raise Exception, 'record_id == 0'
rows = db(table.id == record_id).select()
if len(rows) == 0 or rows[0].unique_key != unique_key:
raise Exception, 'No record'
=== modified file 'gluon/highlight.py'
--- gluon/highlight.py 2009-07-18 02:52:22 +0000
+++ gluon/highlight.py 2009-07-23 07:10:52 +0000
@@ -50,7 +50,7 @@
elif mode == 'HTML':
self.suppress_tokens = []
else:
- raise SyntaxError
+ raise SyntaxError('Unknown mode: %s' % mode)
self.mode = mode
def c_tokenizer(
=== modified file 'gluon/sql.py'
--- gluon/sql.py 2009-07-18 21:40:44 +0000
+++ gluon/sql.py 2009-07-23 07:24:30 +0000
@@ -797,7 +797,8 @@
m = re.compile('^(?P<dsn>.+)$'
).match(self._uri[skip:])
if not m:
- raise SyntaxError, 'Parsing has no result'
+ raise SyntaxError, \
+ 'Parsing uri string(%s) has no result' % (self._uri[skip:])
dsn = m.group('dsn')
if not dsn:
raise SyntaxError, 'DSN required'
@@ -986,7 +987,7 @@
for key in args:
if key != 'migrate':
- raise SyntaxError, 'invalid table attribute: %s' % key
+ raise SyntaxError, 'invalid table \'%s\' attribute: %s' % (tablename, key)
migrate = args.get('migrate',True)
tablename = cleanup(tablename)
if hasattr(self,tablename) or tablename[0] == '_':
@@ -1200,9 +1201,9 @@
if isinstance(field.type,str) and field.type[:10] == 'reference ':
referenced = field.type[10:].strip()
if not referenced:
- raise SyntaxError, 'SQLTable: reference to nothing!'
+ raise SyntaxError, 'SQLTable: reference to nothing: %s' % referenced
if not referenced in self._db:
- raise SyntaxError, 'SQLTable: table does not exist'
+ raise SyntaxError, 'SQLTable: table \'%s\'does not exist' % referenced
referee = self._db[referenced]
if self._tablename in referee.fields:
raise SyntaxError, 'SQLField: table %s has same name as a field in referenced table %s' % (self._tablename, referee._tablename)
@@ -1848,7 +1849,7 @@
try:
m = regex_content.match(name)
if not m or not self.isattachment:
- raise TypeError
+ raise TypeError('Can\'t retrieve %s' % name)
filename = base64.b16decode(m.group('name'), True)
filename = regex_cleanup_fn.sub('_', filename)
except (TypeError, AttributeError):
@@ -1989,7 +1990,7 @@
self.sql = '%s %s' % (left,
left._db._translator['is not null'])
else:
- raise SyntaxError, 'do not know what to do'
+ raise SyntaxError, 'Operation %s can\'t be used with None' % op
elif op == ' IN ':
if isinstance(right, str):
self.sql = '%s%s(%s)' % (left, op, right[:-1])
@@ -1998,7 +1999,7 @@
for i in right])
self.sql = '%s%s(%s)' % (left, op, r)
else:
- raise SyntaxError, 'do not know what to do'
+ raise SyntaxError, 'Right argument of \'IN\' is not suitable'
elif isinstance(right, (SQLField, SQLXorable)):
self.sql = '%s%s%s' % (left, op, right)
else:
@@ -2507,7 +2508,7 @@
mode = mode.lower()
if not mode in ['object', 'array']:
- raise SyntaxError, 'Invalid JSON serialization mode.'
+ raise SyntaxError, 'Invalid JSON serialization mode: %s' % mode
def inner_loop(record, col):
(t, f) = col.split('.')
=== modified file 'gluon/sqlhtml.py'
--- gluon/sqlhtml.py 2009-07-18 02:52:22 +0000
+++ gluon/sqlhtml.py 2009-07-23 07:26:15 +0000
@@ -775,7 +775,8 @@
return ret
if record_id and record_id != self.record_id:
- raise SyntaxError, 'user is tampering with form'
+ raise SyntaxError, 'user is tampering with form\'s record_id: ' \
+ '%s != %s' % (record_id, self.record_id)
if requested_delete:
self.table._db(self.table.id == self.record.id).delete()
=== modified file 'gluon/storage.py'
--- gluon/storage.py 2009-07-18 02:52:22 +0000
+++ gluon/storage.py 2009-07-23 07:27:50 +0000
@@ -103,9 +103,9 @@
def __setattr__(self, key, value):
if key != 'lock_keys' and self.get('lock_keys', None)\
and not key in self:
- raise SyntaxError, 'setting key does not exist'
+ raise SyntaxError, 'setting key \'%s\' does not exist' % key
if key != 'lock_values' and self.get('lock_values', None):
- raise SyntaxError, 'setting value cannot be changed'
+ raise SyntaxError, 'setting value cannot be changed: %s' % key
self[key] = value
@@ -117,9 +117,9 @@
def __setattr__(self, key, value):
if key != 'lock_keys' and self.get('lock_keys', None)\
and not key in self:
- raise SyntaxError, 'setting key does not exist'
+ raise SyntaxError, 'setting key \'%s\' does not exist' % key
if key != 'lock_values' and self.get('lock_values', None):
- raise SyntaxError, 'setting value cannot be changed'
+ raise SyntaxError, 'setting value cannot be changed: %s' % key
self[key] = value
def __getattr__(self, key):
=== modified file 'gluon/tools.py'
--- gluon/tools.py 2009-07-18 02:52:22 +0000
+++ gluon/tools.py 2009-07-23 07:29:07 +0000
@@ -621,7 +621,7 @@
elif 'email' in keys:
username = 'email'
else:
- raise SyntaxError, "user must have username of email"
+ raise SyntaxError, "user must have username or email"
table_user = self.settings.table_user
passfield = self.settings.password_field
users = self.db(table_user[username] == keys[username]).select()
=== modified file 'gluon/validators.py'
--- gluon/validators.py 2009-07-18 02:52:22 +0000
+++ gluon/validators.py 2009-07-23 07:31:08 +0000
@@ -1485,7 +1485,8 @@
h = h + 12
if not (h in range(24) and m in range(60) and s
in range(60)):
- raise ValueError
+ raise ValueError\
+ ('Hours or minutes or seconds are outside of allowed range')
value = datetime.time(h, m, s)
return (value, None)
except AttributeError:
=== modified file 'gluon/wsgiserver.py'
--- gluon/wsgiserver.py 2009-07-18 02:52:22 +0000
+++ gluon/wsgiserver.py 2009-07-23 07:32:51 +0000
@@ -818,10 +818,7 @@
if is_reader and thirdarg == 'ssl handshake failure':
return ''
if thirdarg == 'http request':
-
- # The client is talking HTTP to an HTTPS server.
-
- raise NoSSLError()
+ raise NoSSLError('The client is talking HTTP to an HTTPS server')
raise
if time.time() - start > self.ssl_timeout:
raise socket.timeout('timed out')