Skip to content

Catch and log invariant errors when cbmc_invariants_should_throwt is enabled #5225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jeannielynnmoulton
Copy link
Contributor

@jeannielynnmoulton jeannielynnmoulton commented Feb 6, 2020

If cbmc_invariants_should_throwt is enabled, then invariants become
exceptions, and we should log them instead of putting them into the catch
all with no information.

  • Each commit message has a non-empty body, explaining why the change was made.
  • Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@jeannielynnmoulton jeannielynnmoulton changed the title Catch and log invariant errors. Catch and log invariant errors when cbmc_invariants_should_throwt is enabled Feb 6, 2020
@martin-cs
Copy link
Collaborator

This patch is an improvement but I think this shows a weakness of cbmc_invariants_should_throwt. There are two reasons the original invariant design did not throw exceptions:

  1. The design of CPROVER and the intended use of invariants mean that invariant failures are non-recoverable. You should stop immediately and print out an error -- which is exactly what the default implementation does.

  2. If it throws an exception people think they can be clever and catch it and then they wind up hiding errors. There have been a number of incidence of this. This patch removes a place it can happen and that is good. The way to remove all places it can happen is to not throw an exception on invariant failure.

If cbmc_invariants_should_throwt is enabled, then invariants become
exceptions and we should log them instead of putting them into the catch
all with no information.
@jeannielynnmoulton jeannielynnmoulton force-pushed the jeannie/LogInvariantViolations branch from 0c103b9 to fe1290a Compare February 6, 2020 17:36
@hannes-steffenhagen-diffblue
Copy link
Contributor

hannes-steffenhagen-diffblue commented Feb 10, 2020

@martin-cs Invariant failures are usually unrecoverable, but most of them aren’t fatal. Having invariants throw is useful for unit testing (where you can mark a test as failing instead of having to comment it out entirely, because otherwise abort aborts the entire test suite) and for providing additional diagnostic information on invariant failure (which may not be local to the point where the invariant failure actually occurs). I agree that during normal operation abort is a sensible default, but there are genuine reasons why you might not want that to happen.

Code that blanket catches exceptions (other than to log information and rethrow or abort) ideally shouldn’t pass code review.

@jeannielynnmoulton jeannielynnmoulton merged commit 277e8a1 into diffblue:develop Feb 10, 2020
@jeannielynnmoulton jeannielynnmoulton deleted the jeannie/LogInvariantViolations branch February 10, 2020 17:32
@martin-cs
Copy link
Collaborator

martin-cs commented Feb 11, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants