diff --git a/style.md b/style.md index 145b844..52ebe2b 100644 --- a/style.md +++ b/style.md @@ -303,9 +303,20 @@ arena.reset(); // Reset arena memory - **Return codes** for expected errors - **Exceptions** only for exceptional circumstances - **fprintf + abort()** for unrecoverable errors +- **Error messages are for humans only** - never parse error message strings programmatically +- **Error codes are the contract** - use enums/codes for programmatic error handling ```cpp enum class ParseResult { Success, InvalidJson, MissingField }; +// Good: Test error codes (part of contract) +auto result = parser.parse(data); +if (result == ParseResult::InvalidJson) { + // Handle programmatically +} + +// Bad: Don't test or parse error message strings +// CHECK(parser.get_error() == "Expected '}' at line 5"); // BRITTLE! + if (!memory) { std::fprintf(stderr, "ArenaAllocator: Failed to allocate memory\n"); std::abort();