Skip to content

Commit 363b9c2

Browse files
committed
errors: added __str__ methods
1 parent 2626a13 commit 363b9c2

24 files changed

+213
-54
lines changed

files/inp/invalid_02.inp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Bad INP File!
2+
1 0 3 4 imp:@=1
3+
4+
1 so 3
5+
sdef
6+
nps 10

src/pymcnp/Inp.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,6 @@ def _preprocess(source: str):
204204
source = re.sub(r'\t', ' ', source)
205205
source = source.strip()
206206

207-
print(repr(source))
208-
209207
return source
210208

211209
@property

src/pymcnp/_cli/_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ def disclaimer():
4848
Prints disclaimer message.
4949
"""
5050

51-
warning('PyMCNP is in active development! Please, double check eveything works. Reports error on [underline][link=https://github.com/FSIBT/PyMCNP/issues]GitHub[/][/].')
51+
warning('PyMCNP is in active development! Please, double-check everything works. Reports error on [underline][link=https://github.com/FSIBT/PyMCNP/issues]GitHub[/][/].')

src/pymcnp/_cli/convert.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def main() -> None:
4343
except errors.CliError as err:
4444
_io.error(str(err))
4545
exit(2)
46+
# except errors.TypesError as err:
47+
# _io.error(str(err))
48+
# exit(3)
4649

4750
# Converting!
4851
if args['--csv']:

src/pymcnp/_cli/plot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,13 @@ def main() -> None:
4747

4848
matplotlib.pyplot.close()
4949
except errors.OutpError as err:
50-
_io.error(err)
50+
_io.error(str(err))
5151
exit(1)
5252
except errors.CliError as err:
53-
_io.error(err)
53+
_io.error(str(err))
5454
exit(2)
55+
# except errors.TypesError as err:
56+
# _io.error(str(err))
57+
# exit(3)
5558

5659
_io.done()

src/pymcnp/_cli/run.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def main() -> None:
3939
except errors.CliError as err:
4040
_io.error(str(err))
4141
exit(2)
42+
except errors.TypesError as err:
43+
_io.error(str(err))
44+
exit(3)
4245

4346
# Running!
4447
try:

src/pymcnp/_cli/visualize.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ def main() -> None:
4343
except errors.CliError as err:
4444
_io.error(str(err))
4545
exit(2)
46+
except errors.TypesError as err:
47+
_io.error(str(err))
48+
exit(3)
4649

4750
if not (args['--cells'] or args['--surfaces'] or args['--cell'] or args['--surface']):
4851
args['--cells'] = True
@@ -51,40 +54,44 @@ def main() -> None:
5154
args['--surface'] = [str(surface.number) for surface in inpt.surfaces if isinstance(surface, inp.Surface)]
5255

5356
# Visualizing!
54-
if args['--cells']:
55-
if args['--pdf']:
56-
visualize.to_pdf_cells(_io.get_outfile(file, 'pdf', 'cells'))
57-
else:
58-
plot = visualize.to_show_cells()
59-
60-
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
61-
plot.show()
62-
63-
if args['--surfaces']:
64-
if args['--pdf']:
65-
visualize.to_pdf_surfaces(_io.get_outfile(file, 'pdf', 'surfaces'))
66-
else:
67-
plot = visualize.to_show_surfaces()
68-
69-
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
70-
plot.show()
71-
72-
for number in args['--cell']:
73-
if args['--pdf']:
74-
visualize.to_pdf_cells(_io.get_outfile(file, 'pdf', f'cell_{number}'))
75-
else:
76-
plot = visualize.to_show_cell(number)
77-
78-
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
79-
plot.show()
80-
81-
for number in args['--surface']:
82-
if args['--pdf']:
83-
visualize.to_pdf_cells(_io.get_outfile(file, 'pdf', f'surface_{number}'))
84-
else:
85-
plot = visualize.to_show_surface(number)
86-
87-
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
88-
plot.show()
57+
try:
58+
if args['--cells']:
59+
if args['--pdf']:
60+
visualize.to_pdf_cells(_io.get_outfile(file, 'pdf', 'cells'))
61+
else:
62+
plot = visualize.to_show_cells()
63+
64+
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
65+
plot.show()
66+
67+
if args['--surfaces']:
68+
if args['--pdf']:
69+
visualize.to_pdf_surfaces(_io.get_outfile(file, 'pdf', 'surfaces'))
70+
else:
71+
plot = visualize.to_show_surfaces()
72+
73+
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
74+
plot.show()
75+
76+
for number in args['--cell']:
77+
if args['--pdf']:
78+
visualize.to_pdf_cells(_io.get_outfile(file, 'pdf', f'cell_{number}'))
79+
else:
80+
plot = visualize.to_show_cell(number)
81+
82+
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
83+
plot.show()
84+
85+
for number in args['--surface']:
86+
if args['--pdf']:
87+
visualize.to_pdf_cells(_io.get_outfile(file, 'pdf', f'surface_{number}'))
88+
else:
89+
plot = visualize.to_show_surface(number)
90+
91+
if 'PYTEST_CURRENT_TEST' not in os.environ: # pragma: no cover
92+
plot.show()
93+
except errors.CliError as err:
94+
_io.error(str(err))
95+
exit(3)
8996

9097
_io.done()

src/pymcnp/errors/CliError.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
class CliCode(_error.Code):
55
"""
66
Represents ``cli`` error codes.
7-
8-
Notes:
9-
0x - Runtime
10-
x0 - Check
11-
x1 - Convert
12-
x2 - Plot
13-
x3 - Run
14-
x4 - Visualize
157
"""
168

179
RUNTIME_PATH = 0
@@ -23,4 +15,11 @@ class CliError(_error.Error):
2315
Represents ``cli`` errors.
2416
"""
2517

26-
pass
18+
def __str__(self):
19+
info = str(self.info).split('\n')
20+
info = '\n> '.join(info[: _error.CUTOFF] + ['...'] if len(info) > _error.CUTOFF else info)
21+
22+
if self.code == CliCode.RUNTIME_PATH:
23+
return f'Bad path.\n> {info}'
24+
if self.code == CliCode.RUNTIME_DOER:
25+
return f'Bad parameter.\n> {info}'

src/pymcnp/errors/InpError.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,23 @@ class InpError(_error.Error):
3030
Represents ``inp`` errors.
3131
"""
3232

33-
pass
33+
def __str__(self):
34+
info = str(self.info).split('\n')
35+
info = '\n> '.join(info[: _error.CUTOFF] + ['...'] if len(info) > _error.CUTOFF else info)
36+
37+
if self.code == InpCode.SYNTAX_FILE:
38+
return f'INP file not recognized.\n> {info}'
39+
if self.code == InpCode.SYNTAX_CARD:
40+
return f'INP card not recognized.\n> {info}'
41+
if self.code == InpCode.SYNTAX_OPTION:
42+
return f'INP option not recognized.\n> {info}'
43+
if self.code == InpCode.SYNTAX_ENTRY:
44+
return f'INP entry not recognized.\n> {info}'
45+
if self.code == InpCode.SEMANTICS_FILE:
46+
return f'Invalid INP file.\n> {info}'
47+
if self.code == InpCode.SEMANTICS_CARD:
48+
return f'Invalid INP card.\n> {info}'
49+
if self.code == InpCode.SEMANTICS_OPTION:
50+
return f'Invalid INP option.\n> {info}'
51+
if self.code == InpCode.SEMANTICS_ENTRY:
52+
return f'Invalid INP entry.\n> {info}'

src/pymcnp/errors/MeshtalError.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@ class MeshtalError(_error.Error):
2424
Represents ``meshtal`` errors.
2525
"""
2626

27-
pass
27+
def __str__(self):
28+
info = str(self.info).split('\n')
29+
info = '\n> '.join(info[: _error.CUTOFF] + ['...'] if len(info) > _error.CUTOFF else info)
30+
31+
if self.code == MeshtalCode.SYNTAX_FILE:
32+
return f'MESHTAL file not recognized.\n> {info}'
33+
if self.code == MeshtalCode.SYNTAX_BLOCK:
34+
return f'MESHTAL table not recognized.\n> {info}'
35+
if self.code == MeshtalCode.SYNTAX_LINE:
36+
return f'MESHTAL line not recognized.\n> {info}'
37+
if self.code == MeshtalCode.SEMANTICS_FILE:
38+
return f'Invalid MESHTAL file.\n> {info}'
39+
if self.code == MeshtalCode.SEMANTICS_BLOCK:
40+
return f'Invalid MESHTAL table.\n> {info}'
41+
if self.code == MeshtalCode.SEMANTICS_LINE:
42+
return f'Invalid MESHTAL line.\n> {info}'

0 commit comments

Comments
 (0)