Chromium Code Reviews| Index: sql/connection.h |
| diff --git a/sql/connection.h b/sql/connection.h |
| index 049d7cf5b4e2f9715ffc4b7f67dd2e89dc367bff..c5ab91b74223fc70dc8e618b5c472857864d428b 100644 |
| --- a/sql/connection.h |
| +++ b/sql/connection.h |
| @@ -539,6 +539,54 @@ class SQL_EXPORT Connection { |
| DISALLOW_COPY_AND_ASSIGN(Connection); |
| }; |
| +// Most errors are fatal in debug mode, because usually they indicate |
| +// an inappropriate use of SQL. This makes it challenging to write |
| +// tests for things like recovery from corruption. Use this scoper to |
| +// ignore errors during the current test. This applies globally (to |
| +// all connections). The scoper can be nested, but is not thread-safe. |
| +// |
| +// Specific errors must be ignores, and all ignored errors must be |
|
erikwright (departed)
2013/06/11 18:54:19
Grammar problems to the point that I don't know wh
|
| +// seen. |
| +// |
| +// TODO(shess): Wire things up so this can only be used from tests. |
| +// NOTE(shess): This does not comprehensively suppress errors at this |
| +// time. If your test is handling database errors and you're hitting |
| +// a case not handled, contact me. |
| +// NOTE(shess): If you use this in production code, I will revert you. |
| +class SQL_EXPORT ScopedErrorIgnorer { |
|
erikwright (departed)
2013/06/11 18:54:19
I'd have to scan sql/ to see what the local conven
|
| + public: |
| + ScopedErrorIgnorer(); |
| + ~ScopedErrorIgnorer(); |
| + |
| + // Add an error to ignore. Extended error codes can be ignored |
| + // specifically, or the base can be ignored as a group |
| + // (SQLITE_IOERR_* versus SQLITE_IOERR). |
| + void IgnoreError(int err); |
| + |
| + // Allow containing test to check if the errors were encountered. |
| + // Test is REQUIRED to call this before destruction. |
| + // TODO(shess): How to handle ASSERT_X() cases which cause early |
| + // return in tests? |
| + bool CheckIgnoredErrors(); |
| + |
| + // Check if the error should be ignored. |
| + static bool ShouldIgnoreError(int err); |
| + |
| + private: |
| + // Record whether CheckIgnoredErrors() has been called. |
| + bool checked_; |
| + |
| + // Errors to ignore. |
| + std::set<int> ignore_errors_; |
| + |
| + // Errors which have been ignored. |
| + std::set<int> errors_ignored_; |
| + |
| + ScopedErrorIgnorer* next_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedErrorIgnorer); |
| +}; |
| + |
| } // namespace sql |
| #endif // SQL_CONNECTION_H_ |