##// END OF EJS Templates
revsetlang: add a hint for more useful parse errors...
Ryan McElroy -
r36703:2a258985 default
parent child Browse files
Show More
@@ -539,7 +539,21 b' def foldconcat(tree):'
539 539 return tuple(foldconcat(t) for t in tree)
540 540
541 541 def parse(spec, lookup=None):
542 return _parsewith(spec, lookup=lookup)
542 try:
543 return _parsewith(spec, lookup=lookup)
544 except error.ParseError as inst:
545 if len(inst.args) > 1: # has location
546 # Add 1 to location because unlike templates, revset parse errors
547 # point to the char where the error happened, not the char after.
548 loc = inst.args[1] + 1
549 # Remove newlines -- spaces are equivalent whitespace.
550 spec = spec.replace('\n', ' ')
551 # We want the caret to point to the place in the template that
552 # failed to parse, but in a hint we get a open paren at the
553 # start. Therefore, we print "loc + 1" spaces (instead of "loc")
554 # to line up the caret with the location of the error.
555 inst.hint = spec + '\n' + ' ' * loc + '^ ' + _('here')
556 raise
543 557
544 558 def _quote(s):
545 559 r"""Quote a value in order to make it safe for the revset engine.
@@ -814,6 +814,8 b' check error cases'
814 814 [255]
815 815 $ hg log -r 'followlines(baz, 2:4, startrev=20, descend=[1])'
816 816 hg: parse error at 43: not a prefix: [
817 (followlines(baz, 2:4, startrev=20, descend=[1])
818 ^ here)
817 819 [255]
818 820 $ hg log -r 'followlines(baz, 2:4, startrev=20, descend=a)'
819 821 hg: parse error: descend argument must be a boolean
@@ -142,6 +142,8 b' Invalid :pushrev raises appropriately'
142 142 $ hg --config 'paths.default:pushrev=(' push
143 143 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
144 144 hg: parse error at 1: not a prefix: end
145 ((
146 ^ here)
145 147 [255]
146 148
147 149 $ cd ..
@@ -666,7 +666,11 b' Empty revset will error at the revset la'
666 666
667 667 $ fileset "status(' ', '4', added())"
668 668 hg: parse error at 1: not a prefix: end
669 (
670 ^ here)
669 671 [255]
670 672 $ fileset "status('2', ' ', added())"
671 673 hg: parse error at 1: not a prefix: end
674 (
675 ^ here)
672 676 [255]
@@ -399,6 +399,8 b' quoting needed'
399 399 4
400 400 $ log 'date(this is a test)'
401 401 hg: parse error at 10: unexpected token: symbol
402 (date(this is a test)
403 ^ here)
402 404 [255]
403 405 $ log 'date()'
404 406 hg: parse error: date requires a string
@@ -408,6 +410,8 b' quoting needed'
408 410 [255]
409 411 $ log 'date('
410 412 hg: parse error at 5: not a prefix: end
413 (date(
414 ^ here)
411 415 [255]
412 416 $ log 'date("\xy")'
413 417 hg: parse error: invalid \x escape* (glob)
@@ -614,18 +618,28 b' parse errors of relation, subscript and '
614 618
615 619 $ hg debugrevspec '[0]'
616 620 hg: parse error at 0: not a prefix: [
621 ([0]
622 ^ here)
617 623 [255]
618 624 $ hg debugrevspec '.#'
619 625 hg: parse error at 2: not a prefix: end
626 (.#
627 ^ here)
620 628 [255]
621 629 $ hg debugrevspec '#rel'
622 630 hg: parse error at 0: not a prefix: #
631 (#rel
632 ^ here)
623 633 [255]
624 634 $ hg debugrevspec '.#rel[0'
625 635 hg: parse error at 7: unexpected token: end
636 (.#rel[0
637 ^ here)
626 638 [255]
627 639 $ hg debugrevspec '.]'
628 640 hg: parse error at 1: invalid token
641 (.]
642 ^ here)
629 643 [255]
630 644
631 645 $ hg debugrevspec '.#generations[a]'
@@ -1330,6 +1344,8 b' test author'
1330 1344 6
1331 1345 $ try 'grep(r"\")'
1332 1346 hg: parse error at 7: unterminated string
1347 (grep(r"\")
1348 ^ here)
1333 1349 [255]
1334 1350 $ log 'head()'
1335 1351 0
@@ -2774,3 +2790,14 b' topo.firstbranch should accept any kind '
2774 2790
2775 2791 $ cd ..
2776 2792 $ cd repo
2793
2794 test multiline revset with errors
2795
2796 $ echo > multiline-revset
2797 $ echo '. +' >> multiline-revset
2798 $ echo '.^ +' >> multiline-revset
2799 $ hg log -r "`cat multiline-revset`"
2800 hg: parse error at 9: not a prefix: end
2801 ( . + .^ +
2802 ^ here)
2803 [255]
@@ -690,6 +690,8 b' issue2654: report a parse error if the r'
690 690
691 691 $ log '1 OR 2'
692 692 hg: parse error at 2: invalid token
693 (1 OR 2
694 ^ here)
693 695 [255]
694 696
695 697 or operator should preserve ordering:
@@ -1562,6 +1564,8 b' test in problematic encoding'
1562 1564 test error message of bad revset
1563 1565 $ hg log -r 'foo\\'
1564 1566 hg: parse error at 3: syntax error in revset 'foo\\'
1567 (foo\\
1568 ^ here)
1565 1569 [255]
1566 1570
1567 1571 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now