Skip to content

Commit

Permalink
more guards in loop; syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer committed Aug 29, 2023
1 parent 8297120 commit 256832f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
21 changes: 7 additions & 14 deletions docker-qgis/process_projectfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def from_exception_msg(
class ErrorReport(NamedTuple):
line_n: int
column_n: int
culprit: str
char: str
line: str

@classmethod
Expand All @@ -62,23 +62,16 @@ def create_from(
# further decoding errors in case it is not utf-8 compliant
left = location.column - 1
right = location.column + 1
culprit = repr(line[left:right])
line_str = repr(line.strip())
return cls(
line=line_str,
culprit=culprit,
line=repr(line.strip()),
char=repr(line[left:right]),
line_n=location.line,
column_n=location.column,
)
return None

def render(self) -> str:
return f"""
\nLine: {self.line_n}
\nColumn: {self.column_n}
\nInvalid symbol: {self.culprit}
\nFull line: {self.line}
"""
return f"Unable to parse character on line {self.line_n}, column {self.column_n}: {self.char}. Full line reads: {self.line}."


def check_valid_project_file(project_filename: Path) -> None:
Expand All @@ -94,9 +87,9 @@ def check_valid_project_file(project_filename: Path) -> None:
continue
except ElementTree.ParseError as error:
error_msg = str(error)
contextualized_error = ErrorReport.create_from(error_msg, fh)
if contextualized_error:
xml_error = contextualized_error.render()
report = ErrorReport.create_from(error_msg, fh)
if report:
xml_error = report.render()
else:
xml_error = error_msg
raise InvalidXmlFileException(
Expand Down
10 changes: 6 additions & 4 deletions docker-qgis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def run_workflow(
feedback["error_type"] = "UNKNOWN"
feedback["error_class"] = type(err).__name__
finally:
(_type, _value, tb) = sys.exc_info()
_type, _value, tb = sys.exc_info()
feedback["error_stack"] = traceback.format_tb(tb)
feedback["steps"] = []
feedback["outputs"] = {}
Expand All @@ -602,9 +602,11 @@ def run_workflow(
step_feedback["returns"] = step_returns[step.id]
feedback["outputs"][step.id] = {}
for output_name in step.outputs:
feedback["outputs"][step.id][output_name] = step_returns[step.id][
output_name
]
if step.id in feedback["outputs"]:
if output_name in feedback["outputs"][step.id]:
feedback["outputs"][step.id][output_name] = step_returns[
step.id
][output_name]

feedback["steps"].append(step_feedback)

Expand Down

0 comments on commit 256832f

Please sign in to comment.