Skip to content

Commit e61bd09

Browse files
committed
fix: issue2551374 - Add error handling for filter expressions. Fix UI
Errors are now reported using the search template. This should work in most situations. However if the query was generated using an alternate search template, the user may not be able to fix it. I'm not sure how to tell what template was used to submit the search. By the time I handle the error, I don't think I have access to an ok template or error template. Might need to add a new field if this becomes a problem. Also fixed a couple of tests changing the status code to 200 from 400 since we aren't on an error page anymore. Updated user_guide including 3 sample error messages for search expressions and how to understand them.
1 parent d3b1a25 commit e61bd09

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

CHANGES.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ Fixed:
5959
- fixed a crash with roundup-admin perftest password when rounds not set
6060
on command line. (John Rouillard)
6161
- issue2551374 - Add error handling for filter expressions. Filter
62-
expression errors are now reported. The UI needs some work but
63-
even the current code is helpful when debugging filter
64-
expressions. (John Rouillard)
62+
expression errors are now reported. (John Rouillard)
6563

6664
Features:
6765

doc/user_guide.txt

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,45 @@ search page, there's an expression editor. You can access it by
491491
clicking on the ``(expr)`` link, which makes creating these
492492
expressions a bit easier.
493493

494-
Note that errors in your expression (e.g. a missing operand) are
495-
silently ignored and a fallback search is conducted. This is
496-
`considered a bug <https://issues.roundup-tracker.org/issue2551374>`_
497-
and will hopefully be fixed in the future. But at least you can use
498-
this info to understand the search syntax in the URL if you see
499-
something strange.
494+
If your expression has an error, you will be returned to the search
495+
page and an error will be reported. For example using the expression
496+
``1, -3`` to search the nosy property of an issue generates the
497+
following error::
498+
499+
There was an error searching issue by nosy using: [1, -3]. The
500+
operator -3 (and) at position 2 has too few arguments.
501+
502+
The error message gives you the problem element (``-3``), it's meaning
503+
(``and``) and its position: the second element. The problem was caused
504+
because ``and`` requires two arguments, but only one argument (``1``)
505+
was given.
506+
507+
Another error message::
508+
509+
There was an error searching issue by status using: [1, 2, -3,
510+
-3]. The operator -3 (and) at position 4 has too few arguments.
511+
512+
reports that the second ``-3`` in the 4th position is the problem
513+
operator. Note that this search expression will never return any
514+
values. This is because ``status`` is a single value (link) type
515+
property. It can't have the values ``1`` and ``2``, so the expression
516+
``1,2,-3`` will never return an issue.
517+
518+
In the examples above, the error was caused by not having enough
519+
arguments. However you can also have too many arguments. An example of
520+
this type of message is::
521+
522+
There was an error searching issue by nosy using: [4, 5, 1, 2, -3,
523+
-3]. There are too many arguments for the existing operators. The
524+
values on the stack are: [Value 4, (Value 5 AND (Value 1 AND Value
525+
2))]
526+
527+
This message gives you the expression as far as it was able to compose
528+
it, but value 1 is not combined with the rest of the expression. So
529+
another binary operator is needed to complete the expression.
530+
531+
If you have multiple incorrect expressions in your search, only one
532+
expression will be reported each time you submit the search.
500533

501534
Using the Classhelper
502535
---------------------

roundup/cgi/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2232,7 +2232,8 @@ def renderContext(self):
22322232
result = self.renderError(e.args[0])
22332233
except ExpressionError as e:
22342234
self.add_error_message(str(e))
2235-
result = self.renderError(str(e))
2235+
self.template = "search"
2236+
self.write_html(self.renderContext())
22362237

22372238
if 'Content-Type' not in self.additional_headers:
22382239
self.additional_headers['Content-Type'] = pt.content_type

test/test_liveserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def test_broken_query(self):
380380
'[-2]. The operator -2 (not) at position 1 has '
381381
'too few arguments.',
382382
f.text)
383-
self.assertEqual(f.status_code, 400)
383+
self.assertEqual(f.status_code, 200)
384384

385385
def test_broken_multiink_query(self):
386386
# query multilink item
@@ -398,7 +398,7 @@ def test_broken_multiink_query(self):
398398
'[-3]. The operator -3 (and) at position 1 has '
399399
'too few arguments.',
400400
f.text)
401-
self.assertEqual(f.status_code, 400)
401+
self.assertEqual(f.status_code, 200)
402402

403403
def test_start_page(self):
404404
""" simple test that verifies that the server can serve a start page.

0 commit comments

Comments
 (0)