Skip to content

Commit

Permalink
Error handling for per-file language config.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Aug 19, 2022
1 parent 2a4f404 commit 752a709
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions atest/robot/parsing/translations.robot
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Per file configuration with multiple languages
${tc} = Check Test Case ตัวอย่าง
Should Be Equal ${tc.doc} приклад

Invalid per file configuration
Error in file 0 parsing/translations/per_file_config/many.robot 6
... Invalid language configuration: No language with name 'invalid' found.

Per file configuration bleeds to other files
[Documentation] This is a technical limitation and will hopefully change!
Run Tests ${EMPTY} parsing/translations/per_file_config/fi.robot parsing/translations/finnish/tests.robot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LANGUAGE: Brazilian Portuguese

This is not language: config

language: THAI language: ukrainian
language: THAI language: invalid language: ukrainian

*** Einstellungen ***
Documentação Exemplo
Expand Down
5 changes: 1 addition & 4 deletions src/robot/conf/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ def _add_language(self, lang):
self.bdd_prefixes |= {p.title() for p in lang.bdd_prefixes}

def add_language(self, name):
try:
lang = Language.from_name(name)
except ValueError:
raise # FIXME: Proper error handling!!
lang = Language.from_name(name)
self._add_language(lang)

def _get_languages(self, languages):
Expand Down
10 changes: 9 additions & 1 deletion src/robot/parsing/lexer/statementlexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ def input(self, statement):
for token in statement:
match = self.language.match(token.value)
if match:
self.ctx.add_language(match.group(1).strip())
try:
self.ctx.add_language(match.group(1).strip())
except ValueError as err:
token.set_error(f'Invalid language configuration: {err}')

def lex(self):
for token in self.statement:
if not token.type:
token.type = self.token_type


class SettingLexer(StatementLexer):
Expand Down

0 comments on commit 752a709

Please sign in to comment.