Friendly error messages

AvantPy aims to provide friendlier feedback when an exception is raised than what is done by Python. Such feedback will also be available in languages other than English.

Note

The content of this page is generated by running tb_pyupper.py located in the tests/ directory. This needs to be done explicitly, independently of updating the documentation using Sphinx.

AvantPy version: 0.0.15a Python version: 3.7.3

IfNobreakError

AvantPy syntax error:
    IfNobreakError: Keyword nobreak found matching if/elif

The AvantPy 'NOBREAK' keyword cannot be used in
an 'IF/ELIF/ELSE' clause (Python: if/elif/else).

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_if_nobreak.pyupper'
beyond the location indicated below by --> and ^.

   1: '''Should raise IfNobreakError'''
   2: if True:
   3:     pass
-->4: NOBREAK:
            ^

MismatchedBracketsError

AvantPy syntax error:
    MismatchedBracketsError: Closing bracket found matching a different opening one.

The opening ( does not match the closing ].

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_mismatched_brackets.pyupper'
beyond the location indicated below by --> and ^.

    7:     7,
    8:     8,
    9:     9,
-->10: ]
       ^

MissingLeftBracketError

AvantPy syntax error:
    MissingLeftBracketError: Closing bracket found with no matching opening one

The closing ) does not match anything.

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_missing_left_bracket.pyupper'
beyond the location indicated below by --> and ^.

   2: a = (1,
   3:     2,
   4:     3, 4,)
-->5:     )
          ^

MissingRepeatColonError

AvantPy syntax error:
    MissingRepeatColonError: Missing colon on line beginning with repeat

A statement beginning with the 'REPEAT' keyword must be on
a single line ending with a colon (:) that indicates the beginning of
an indented block of code, with no other colon appearing on that line.

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_missing_repeat_colon.pyupper'
beyond the location indicated below by --> and ^.

   1: '''Should raise MissingRepeatColonError'''
   2: x = 0
-->3: REPEAT UNTIL (x ==
                        ^

MissingRepeatError

AvantPy syntax error:
    MissingRepeatError: until and forever must be preceeded by repeat

The AvantPy 'UNTIL'' keyword can be used only whenpreceded by 'REPEAT'.

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_missing_repeat.pyupper'
beyond the location indicated below by --> and ^.

   1: '''Should raise MissingRepeatError'''
   2: x = 0
-->3: UNTIL x == 2:
          ^

NameError

Python exception:
    NameError: name 'c' is not defined

A NameError exception indicates that a variable or
function name is not known to Python.
Most often, this is because there is a spelling mistake.
However, sometimes it is because the name is used
before being defined or given a value.

Likely cause:
    In your program, the unknown name is 'c'.

Execution stopped on line 4 of file 'AVANTPY-TESTS:\pyupper\raise_name_error.pyupper'.

   1: """Should raise NameError"""
   2:
   3: a = 1
-->4: b = c
   5: d = 3

NobreakFirstError

AvantPy syntax error:
    NobreakFirstError: nobreak must be first statement on a line

The AvantPy 'NOBREAK' keyword can be used instead of 'ELSE'
(Python: else) only when it begins a new statement in
'FOR/WHILE' loops (Python: for/while).


Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_nobreak_first.pyupper'
beyond the location indicated below by --> and ^.

   1: '''Should raise NobreakFirstError'''
   2: # Need to prevent NOBREAK being replaced by 'else' in this situation.
-->3: a = 1 if True NOBREAK 3
                          ^

NobreakSyntaxError

AvantPy syntax error:
    NobreakSyntaxError: Keyword nobreak not matching a valid block

The AvantPy 'NOBREAK' keyword can only be used as a replacement
of 'ELSE' (Python: else) with a matching 'FOR' or
'WHILE' loop (Python: for/while).

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_nobreak_syntax.pyupper'
beyond the location indicated below by --> and ^.

   1: '''Should raise NobreakSyntaxError'''
   2: # Need to prevent NOBREAK being replaced by 'else' in this situation.
   3: a = 1
-->4: NOBREAK: pass
            ^

RepeatFirstError

AvantPy syntax error:
    RepeatFirstError: repeat must be first statement on a line

The AvantPy 'REPEAT' keyword can only be used to begin
a new loop (Python: equivalent to 'for' or 'while' loop).

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_repeat_first.pyupper'
beyond the location indicated below by --> and ^.

   1: '''Should raise RepeatFirstError'''
   2: # Catch an early case of using REPEAT not to begin a loop
-->3: a = REPEAT
               ^

TryNobreakError

AvantPy syntax error:
    TryNobreakError: Keyword nobreak found matching try/except

The AvantPy 'NOBREAK' keyword cannot be used in
a 'TRY/EXCEPT/ELSE/FINALLY' clause
(Python: try/except/else/finally).

Python could not parse the file 'AVANTPY-TESTS:\pyupper\raise_try_nobreak.pyupper'
beyond the location indicated below by --> and ^.

    4:         A = 1
    5:     EXCEPT:
    6:         A = 2
--> 7:     NOBREAK:
                 ^

UnknownDialectError

AvantPy exception:
    UnknownDialectError: Unknown dialect pyxx

The following unknown dialect was requested: pyxx.

The known dialects are: ['pyen', 'pyes', 'pyfr', 'pyupper'].

Execution stopped on line 13 of file 'AVANTPY-TESTS:\pyupper\raise_unknown_dialect.pyupper'.

   10:
   11: from avantpy import session
   12:
-->13: session.state.set_dialect('pyxx')
   14:

session: <module 'avantpy.session' from 'C:\\Users\\an...>

Exception raised on line 134 of file 'AVANTPY:\avantpy\session.py'.

   132:         if not self.is_dialect(dialect):
   133:             raise exceptions.UnknownDialectError(
-->134:                 "Unknown dialect %s" % dialect, (dialect, self.all_dialects())
   135:             )

dialect: 'pyxx'
self: <avantpy.session._State object>

UnknownLanguageError

AvantPy exception:
    UnknownLanguageError: Unknown language xx

The following unknown languages was requested: xx.

The known dialects are: {'en', 'fr'}.

Execution stopped on line 13 of file 'AVANTPY-TESTS:\pyupper\raise_unknown_language.pyupper'.

   10:
   11: from avantpy import session
   12:
-->13: session.state.set_lang('xx')
   14:

session: <module 'avantpy.session' from 'C:\\Users\\an...>

Exception raised on line 159 of file 'AVANTPY:\avantpy\session.py'.

   157:         if not self.is_lang(lang):
   158:             raise exceptions.UnknownLanguageError(
-->159:                 "Unknown language %s" % lang, (lang, self.languages)
   160:             )

lang: 'xx'
self: <avantpy.session._State object>