Skip to content

Commit 81a6b3b

Browse files
authored
Enhance error handling in CacheFile methods
Add error logging for file operations in CacheFile.
1 parent afd0930 commit 81a6b3b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/src/CacheFile.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ CacheFile::CacheFile(const std::string &path, bool autoDelete)
3636
file_ = nullptr;
3737
}
3838
#endif
39+
if (!file_)
40+
LOG_SYSERR << "CacheFile fopen:";
3941
}
4042

4143
CacheFile::~CacheFile()
@@ -63,7 +65,10 @@ CacheFile::~CacheFile()
6365
void CacheFile::append(const char *data, size_t length)
6466
{
6567
if (file_)
66-
fwrite(data, length, 1, file_);
68+
{
69+
if (!fwrite(data, length, 1, file_))
70+
LOG_SYSERR << "CacheFile append:";
71+
}
6772
}
6873

6974
size_t CacheFile::length()
@@ -95,7 +100,7 @@ char *CacheFile::data()
95100
if (data_ == MAP_FAILED)
96101
{
97102
data_ = nullptr;
98-
LOG_SYSERR << "mmap:";
103+
LOG_SYSERR << "CacheFile mmap:";
99104
}
100105
}
101106
return data_;

0 commit comments

Comments
 (0)