Skip to content

Commit c11365c

Browse files
authored
Iss632 after rebase on future (#721)
* refact branch rebase off of future; introduce custom error (UnparallelizableError and AdjLineNoteImplemented Error) caught before general errors, introduce custom error to ast_to_ir and ir in compiler at appropriate places with more detail error messages Signed-off-by: YUUU23 <[email protected]> * refactor: import custom error to ast_to_ir, raise unparallelizable err in pash_compiler Signed-off-by: YUUU23 <[email protected]> * refactor: put all expansion custom error from the sh_expand library (expand.py file) under one ExpansionError class in custom_error to catch and log these errors separately Signed-off-by: YUUU23 <[email protected]> * fix: remove duplicated ExpansionError in excepts (compile_ir) Signed-off-by: YUUU23 <[email protected]> * refactor: import ExpansionError (ExpansionError class initiated within expand package Signed-off-by: YUUU23 <[email protected]> * delete: remove expand.py changes as it will be changed in the original package Signed-off-by: YUUU23 <[email protected]> * fix: import expansion error Signed-off-by: YUUU23 <[email protected]> --------- Signed-off-by: YUUU23 <[email protected]>
1 parent 14b58e9 commit c11365c

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

compiler/ast_to_ir.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from util import *
99
from parse import from_ast_objects_to_shell
1010

11+
from custom_error import *
12+
1113
## TODO: Separate the ir stuff to the bare minimum and
1214
## try to move this to the shell_ast folder.
1315

@@ -159,7 +161,7 @@ def combine_pipe(ast_nodes):
159161
else:
160162
## If any part of the pipe is not an IR, the compilation must fail.
161163
log("Node: {} is not pure".format(ast_nodes[0]))
162-
raise Exception("Not pure node in pipe")
164+
raise UnparallelizableError("Node: {} is not a pure node in pipe".format(ast_nodes[0]))
163165

164166
## Combine the rest of the nodes
165167
for ast_node in ast_nodes[1:]:
@@ -168,7 +170,7 @@ def combine_pipe(ast_nodes):
168170
else:
169171
## If any part of the pipe is not an IR, the compilation must fail.
170172
log("Node: {} is not pure".format(ast_nodes))
171-
raise Exception("Not pure node in pipe")
173+
raise UnparallelizableError("This specific node: {} is not a pure node in pipe".format(ast_node))
172174

173175
return [combined_nodes]
174176

compiler/custom_error.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class UnparallelizableError(Exception):
2+
pass
3+
4+
class AdjLineNotImplementedError(Exception):
5+
pass

compiler/ir.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
from shell_ast.ast_util import *
4040
from util import *
41+
from custom_error import *
4142

4243
import config
4344

@@ -242,11 +243,11 @@ def compile_command_to_DFG(fileIdGen, command, options, redirections=None):
242243
command_invocation
243244
)
244245
if io_info is None:
245-
raise Exception(
246+
raise UnparallelizableError(
246247
f"InputOutputInformation for {format_arg_chars(command)} not provided so considered side-effectful."
247248
)
248249
if io_info.has_other_outputs():
249-
raise Exception(
250+
raise UnparallelizableError(
250251
f"Command {format_arg_chars(command)} has outputs other than streaming."
251252
)
252253
para_info: ParallelizabilityInfo = (
@@ -840,7 +841,7 @@ def apply_parallelization_to_node(
840841
node_id, parallelizer, fileIdGen, fan_out
841842
)
842843
else:
843-
raise Exception("Splitter not yet implemented")
844+
raise UnparallelizableError("Splitter not yet implemented for command: {}".format(self.get_node(node_id=node_id).cmd_invocation_with_io_vars.cmd_name))
844845

845846
def apply_round_robin_parallelization_to_node(
846847
self, node_id, parallelizer, fileIdGen, fan_out, r_split_batch_size
@@ -849,11 +850,11 @@ def apply_round_robin_parallelization_to_node(
849850
# currently, this cannot be done since splitter etc. would be added...
850851
aggregator_spec = parallelizer.get_aggregator_spec()
851852
if aggregator_spec.is_aggregator_spec_adj_lines_merge():
852-
raise Exception("adj_lines_merge not yet implemented in PaSh")
853+
raise AdjLineNotImplementedError("adj_lines_merge not yet implemented in PaSh")
853854
elif aggregator_spec.is_aggregator_spec_adj_lines_seq():
854-
raise Exception("adj_lines_seq not yet implemented in PaSh")
855+
raise AdjLineNotImplementedError("adj_lines_seq not yet implemented in PaSh")
855856
elif aggregator_spec.is_aggregator_spec_adj_lines_func():
856-
raise Exception("adj_lines_func not yet implemented in PaSh")
857+
raise AdjLineNotImplementedError("adj_lines_func not yet implemented in PaSh")
857858
# END of what to move
858859

859860
node = self.get_node(node_id)
@@ -1192,7 +1193,7 @@ def introduce_aggregators_for_consec_chunks(
11921193
fileIdGen,
11931194
)
11941195
else:
1195-
raise Exception("aggregator kind not yet implemented")
1196+
raise UnparallelizableError("aggregator kind not yet implemented for command: {}".format(original_cmd_invocation_with_io_vars.cmd_name))
11961197
else: # we got auxiliary information
11971198
assert parallelizer.core_aggregator_spec.is_aggregator_spec_custom_2_ary()
11981199
map_in_aggregator_ids = in_aggregator_ids

compiler/pash_compiler.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
from datetime import datetime
55

66
from sh_expand import env_vars_util
7+
from sh_expand.expand import ExpansionError
78

89
import config
910
from ir import *
1011
from ast_to_ir import compile_asts
1112
from ir_to_ast import to_shell
1213
from pash_graphviz import maybe_generate_graphviz
1314
from util import *
15+
from custom_error import *
1416

1517
from definitions.ir.aggregator_node import *
1618

@@ -92,9 +94,17 @@ def compile_ir(ir_filename, compiled_script_file, args, compiler_config):
9294
ret = compile_optimize_output_script(
9395
ir_filename, compiled_script_file, args, compiler_config
9496
)
97+
except ExpansionError as e:
98+
log("WARNING: Exception caught because some region(s) are not expandable and therefore unparallelizable:", e)
99+
except UnparallelizableError as e:
100+
log("WARNING: Exception caught because some region(s) are unparallelizable:", e)
101+
# log(traceback.format_exc()) # uncomment for exact trace report (PaSh user should see informative messages for unparellizable regions)
102+
except (AdjLineNotImplementedError, NotImplementedError) as e:
103+
log("WARNING: Exception caught because some part is not implemented:", e)
104+
log(traceback.format_exc())
95105
except Exception as e:
96106
log("WARNING: Exception caught:", e)
97-
# traceback.print_exc()
107+
log(traceback.format_exc())
98108

99109
return ret
100110

@@ -142,7 +152,7 @@ def compile_optimize_output_script(
142152

143153
ret = optimized_ast_or_ir
144154
else:
145-
raise Exception("Script failed to compile!")
155+
raise UnparallelizableError("Script failed to compile!")
146156

147157
return ret
148158

0 commit comments

Comments
 (0)