From 2da2e5dc390a7478bfabbb4eadc2f969742c7b1f Mon Sep 17 00:00:00 2001 From: CodingSuen Date: Mon, 24 Oct 2022 10:41:49 +0800 Subject: [PATCH] fix(tianmu): feature: The error display is too general, and the cause of the error cannot be clearly located #706 --- storage/tianmu/system/file.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/storage/tianmu/system/file.cpp b/storage/tianmu/system/file.cpp index 72de2bb54..30df5f1dd 100644 --- a/storage/tianmu/system/file.cpp +++ b/storage/tianmu/system/file.cpp @@ -27,14 +27,17 @@ int TianmuFile::Open(std::string const &file, int flags, mode_t mode) { name_ = file; fd_ = open(file.c_str(), flags, mode); - if (fd_ == -1) ThrowError(errno); + if (fd_ == -1) + throw common::TIANMUError(common::ErrorCode::FAILED, + "ErrorCode: " + std::to_string(errno) + " - " + strerror(errno)); return fd_; } size_t TianmuFile::Read(void *buf, size_t count) { DEBUG_ASSERT(fd_ != -1); auto read_bytes = read(fd_, buf, count); - if (read_bytes == -1) ThrowError(errno); + if (read_bytes == -1) + ThrowError(errno); return read_bytes; } @@ -72,7 +75,8 @@ void TianmuFile::ReadExact(void *buf, size_t count) { size_t read_bytes = 0; while (read_bytes < count) { auto rb = Read((char *)buf + read_bytes, count - read_bytes); - if (rb == 0) break; + if (rb == 0) + break; read_bytes += rb; } if (read_bytes != count) { @@ -86,7 +90,8 @@ void TianmuFile::WriteExact(const void *buf, size_t count) { size_t total_writen_bytes = 0; while (total_writen_bytes < count) { auto writen_bytes = write(fd_, ((char *)buf) + total_writen_bytes, count - total_writen_bytes); - if (writen_bytes == -1) ThrowError(errno); + if (writen_bytes == -1) + ThrowError(errno); total_writen_bytes += writen_bytes; } } @@ -97,7 +102,8 @@ off_t TianmuFile::Seek(off_t pos, int whence) { new_pos = lseek(fd_, pos, whence); - if (new_pos == (off_t)-1) ThrowError(errno); + if (new_pos == (off_t)-1) + ThrowError(errno); return new_pos; } @@ -105,7 +111,8 @@ off_t TianmuFile::Tell() { off_t pos; DEBUG_ASSERT(fd_ != -1); pos = lseek(fd_, 0, SEEK_CUR); - if (pos == (off_t)-1) ThrowError(errno); + if (pos == (off_t)-1) + ThrowError(errno); return pos; }