Skip to content

Commit

Permalink
Capture errors that could occur while printing error information (#298)
Browse files Browse the repository at this point in the history
* Capture errors that could occur while printing error information

* Set Version: 0.2.11

* :s/expection/exception

* Set Version: 0.2.15

---------

Co-authored-by: devops <devops@runtimeverification.com>
  • Loading branch information
dkcumming and devops authored Dec 19, 2023
1 parent 8a3f81a commit 96e53e3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kmir/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "kmir"
version = "0.2.14"
version = "0.2.15"
description = ""
authors = [
"Runtime Verification, Inc. <contact@runtimeverification.com>",
Expand Down
2 changes: 1 addition & 1 deletion kmir/src/kmir/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from .kmir import KMIR

VERSION: Final = '0.2.14'
VERSION: Final = '0.2.15'
47 changes: 42 additions & 5 deletions kmir/src/kmir/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import sys
import traceback
from collections.abc import Callable, Iterable, Iterator
from contextlib import contextmanager
from pathlib import Path
Expand Down Expand Up @@ -193,15 +195,44 @@ def print_failure_info(proof: Proof, kcfg_explore: KCFGExplore, counterexample_i
res_lines.append('')
res_lines.append(f' Node id: {str(node.id)}')

simplified_node, _ = kcfg_explore.cterm_simplify(node.cterm)
simplified_target, _ = kcfg_explore.cterm_simplify(target.cterm)
try:
simplified_node, _ = kcfg_explore.cterm_simplify(node.cterm)
except Exception as err:
process_exception(
err,
res_lines,
' ERROR PRINTING FAILURE INFO: Could not simplify "node.cterm", see stack trace above',
)
try:
simplified_target, _ = kcfg_explore.cterm_simplify(target.cterm)
except Exception as err:
process_exception(
err,
res_lines,
' ERROR PRINTING FAILURE INFO: Could not simplify "target.cterm", see stack trace above',
)

res_lines.append(' Failure reason:')
_, reason = kcfg_explore.implication_failure_reason(simplified_node, simplified_target)
res_lines += [f' {line}' for line in reason.split('\n')]
try:
_, reason = kcfg_explore.implication_failure_reason(simplified_node, simplified_target)
res_lines += [f' {line}' for line in reason.split('\n')]
except Exception as err:
process_exception(
err,
res_lines,
' ERROR PRINTING FAILURE INFO: Could not create "implication_failure_reason", see stack trace above',
)

res_lines.append(' Path condition:')
res_lines += [f' {kcfg_explore.kprint.pretty_print(proof.path_constraints(node.id))}']
try:
res_lines += [f' {kcfg_explore.kprint.pretty_print(proof.path_constraints(node.id))}']
except Exception as err:
process_exception(
err,
res_lines,
' ERROR PRINTING FAILURE INFO: Could not pretty print "proof.path_constraints(node.id)", see stack trace above',
)

if counterexample_info:
res_lines.extend(print_model(node, kcfg_explore))

Expand All @@ -217,6 +248,12 @@ def print_failure_info(proof: Proof, kcfg_explore: KCFGExplore, counterexample_i
raise ValueError('Unknown proof type.')


def process_exception(err: Exception, curr_output: list[str], err_msg: str) -> None:
curr_output.append(err_msg)
print(err, flush=True, file=sys.stderr)
print(traceback.format_exc(), flush=True, file=sys.stderr)


def print_model(node: KCFG.Node, kcfg_explore: KCFGExplore) -> list[str]:
res_lines: list[str] = []
result_subst = kcfg_explore.cterm_get_model(node.cterm)
Expand Down
2 changes: 1 addition & 1 deletion package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.14
0.2.15

0 comments on commit 96e53e3

Please sign in to comment.