Skip to content

Commit db4c056

Browse files
committed
utils/errors: refactored McnpError
1 parent 66a0bda commit db4c056

File tree

490 files changed

+2965
-4883
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

490 files changed

+2965
-4883
lines changed

src/pymcnp/_code.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ def COMMENT(element, t):
8282
).strip()
8383

8484

85-
def ERROR(element, t):
86-
return '\n'.join(
87-
f'{T(t)}McnpError: {attribute.error}.' for attribute in element.attributes
88-
).strip()
89-
90-
9185
def ASSIGN(element, t):
9286
o = ''
9387

@@ -105,7 +99,7 @@ def ASSIGN(element, t):
10599
).strip()
106100

107101

108-
def CHECK(element, t):
102+
def CHECK(element, t, error):
109103
o = ''
110104

111105
for attribute in element.attributes:
@@ -120,7 +114,7 @@ def CHECK(element, t):
120114
else:
121115
o += f'{T(t)}if {attribute.name} is None:\n'
122116

123-
o += f'{T(t)} raise errors.McnpError(errors.McnpCode.{attribute.error}, {attribute.name})\n'
117+
o += f'{T(t)} raise errors.InpError(errors.InpCode.{error}, {attribute.name})\n'
124118

125119
return o.strip()
126120

@@ -275,10 +269,10 @@ def __init__(self, {LIST_NTO(option)}):
275269
``{C(name)}Option_{C(option.name)}``.
276270
277271
Raises:
278-
{ERROR(option, 3)}
272+
InpError: SEMANTICS_OPTION_VALUE.
279273
"""
280274
281-
{CHECK(option, 2)}
275+
{CHECK(option, 2, 'SEMANTICS_OPTION_VALUE')}
282276
283277
self.value: typing.Final[tuple[any]] = types._Tuple([{LIST_N_NSD(option)}])
284278
{ASSIGN(option, 2)}
@@ -295,14 +289,14 @@ def from_mcnp(source: str):
295289
``{C(name)}Option_{C(option.name)}``.
296290
297291
Raises:
298-
McnpError: SYNTAX_{U(name)}_OPTION.
292+
InpError: SYNTAX_{U(name)}_OPTION.
299293
"""
300294
301295
source, comments = _parser.preprocess_inp(source)
302296
tokens = {C(name)}Option_{C(option.name)}._REGEX.match(source)
303297
304298
if not tokens:
305-
raise errors.McnpError(errors.McnpCode.SYNTAX_{U(name)}_OPTION, source)
299+
raise errors.InpError(errors.InpCode.SYNTAX_OPTION, source)
306300
307301
{MATCH(option, 2)}
308302
@@ -360,10 +354,10 @@ def __init__(self, {LIST_NTO(entry)}):
360354
``{C(name)}Entry{C(entry.name)}``.
361355
362356
Raises:
363-
McnpError: SEMANTICS_DATA_ENTRY_VALUE.
357+
InpError: SEMANTICS_ENTRY_VALUE.
364358
"""
365359
366-
{CHECK(entry, 2)}
360+
{CHECK(entry, 2, 'SEMANTICS_ENTRY_VALUE')}
367361
368362
self.parameters: typing.Final[tuple[any]] = types._Tuple([{LIST_N(entry)}])
369363
{ASSIGN(entry, 2)}
@@ -380,14 +374,14 @@ def from_mcnp(source: str):
380374
``{C(name)}Entry_{C(entry.name)}``.
381375
382376
Raises:
383-
McnpError: SYNTAX_{U(name)}_ENTRY.
377+
InpError: SYNTAX_{U(name)}_ENTRY.
384378
"""
385379
386380
source, comments = _parser.preprocess_inp(source)
387381
tokens = {C(name)}Entry_{C(entry.name)}._REGEX.match(' ' + source)
388382
389383
if not tokens:
390-
raise errors.McnpError(errors.McnpCode.SYNTAX_{U(name)}_ENTRY, source)
384+
raise errors.InpError(errors.InpCode.SYNTAX_ENTRY, source)
391385
392386
{MATCH(entry, 2)}
393387

0 commit comments

Comments
 (0)