Standardize error handling patterns and improve ErrorHandler integration.
- Added a comprehensive error propagation standardization report detailing dominant patterns, inconsistencies, and recommended remediations (`docs/audits/error-propagation-standardization.md`). - Integrated `ErrorHandler` into key components, including `main.cc` for robust exception reporting, and added centralized logging to a user state path. - Introduced EINTR-safe syscall wrappers (`SyscallWrappers.h`, `.cc`) to improve resilience of file and metadata operations. - Enhanced `DEVELOPER_GUIDE.md` with an error handling conventions section, covering pattern guidelines and best practices. - Identified gaps in `PieceTable` and internal helpers; deferred fixes with detailed recommendations for improved memory allocation error reporting.
This commit is contained in:
47
SyscallWrappers.h
Normal file
47
SyscallWrappers.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// SyscallWrappers.h - EINTR-safe syscall wrappers for kte
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <cstddef>
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace kte {
|
||||
namespace syscall {
|
||||
// EINTR-safe wrapper for open(2).
|
||||
// Returns file descriptor on success, -1 on failure (errno set).
|
||||
// Automatically retries on EINTR.
|
||||
int Open(const char *path, int flags, mode_t mode = 0);
|
||||
|
||||
// EINTR-safe wrapper for close(2).
|
||||
// Returns 0 on success, -1 on failure (errno set).
|
||||
// Automatically retries on EINTR.
|
||||
// Note: Some systems may not restart close() on EINTR, but we retry anyway
|
||||
// as recommended by POSIX.1-2008.
|
||||
int Close(int fd);
|
||||
|
||||
// EINTR-safe wrapper for fsync(2).
|
||||
// Returns 0 on success, -1 on failure (errno set).
|
||||
// Automatically retries on EINTR.
|
||||
int Fsync(int fd);
|
||||
|
||||
// EINTR-safe wrapper for fstat(2).
|
||||
// Returns 0 on success, -1 on failure (errno set).
|
||||
// Automatically retries on EINTR.
|
||||
int Fstat(int fd, struct stat *buf);
|
||||
|
||||
// EINTR-safe wrapper for fchmod(2).
|
||||
// Returns 0 on success, -1 on failure (errno set).
|
||||
// Automatically retries on EINTR.
|
||||
int Fchmod(int fd, mode_t mode);
|
||||
|
||||
// EINTR-safe wrapper for mkstemp(3).
|
||||
// Returns file descriptor on success, -1 on failure (errno set).
|
||||
// Automatically retries on EINTR.
|
||||
// Note: template_str must be a mutable buffer ending in "XXXXXX".
|
||||
int Mkstemp(char *template_str);
|
||||
|
||||
// Note: rename(2) and unlink(2) are not wrapped because they operate on
|
||||
// filesystem metadata and typically complete atomically without EINTR.
|
||||
// If interrupted, they either succeed or fail without partial state.
|
||||
} // namespace syscall
|
||||
} // namespace kte
|
||||
Reference in New Issue
Block a user