Skip to content

Commit

Permalink
Include filename in FileDataSource errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Nov 27, 2018
1 parent 332672a commit 5fa585d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/filedatasource-unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ int FileDataSource::initialize(const std::string& path, bool owned) {

_fd = open(path.c_str(), O_RDONLY);
if (_fd == -1) {
_lastErrorMessage = "Error opening file: " + toString(errno) + "\n";
_lastErrorMessage = "Error opening file " + path + ": " + toString(errno) + "\n";
return 1;
}
else {
struct stat info = {0};
if (fstat(_fd, &info)) {
_lastErrorMessage = "Error opening path: " + toString(errno) + "\n";
_lastErrorMessage = "Error opening path " + path + ": " + toString(errno) + "\n";
::close(_fd);
return 1;
}

if (S_ISDIR(info.st_mode)) {
_lastErrorMessage = "File data source is a directory.\n";
_lastErrorMessage = "File data source is a directory: " + path + "\n";
::close(_fd);
return 1;
}
Expand All @@ -33,7 +33,7 @@ int FileDataSource::initialize(const std::string& path, bool owned) {
if (owned && unlink(path.c_str())) {
// Print this (on either main or background thread), since we're not
// returning 1 to indicate an error.
err_printf("Couldn't delete temp file: %d\n", errno);
err_printf("Couldn't delete temp file %s: %d\n", path.c_str(), errno);
// It's OK to continue
}

Expand Down
6 changes: 4 additions & 2 deletions src/filedatasource-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ int FileDataSource::initialize(const std::string& path, bool owned) {
NULL);

if (_hFile == INVALID_HANDLE_VALUE) {
_lastErrorMessage = "Error opening file: " + toString(GetLastError()) + "\n";
_lastErrorMessage = "Error opening file " + path + ": " + toString(GetLastError()) + "\n";
return 1;
}

// TODO: Error if it's a directory

if (!GetFileSizeEx(_hFile, &_length)) {
CloseHandle(_hFile);
_lastErrorMessage = "Error retrieving file size: " + toString(GetLastError()) + "\n";
_lastErrorMessage = "Error retrieving file size for " + path + ": " + toString(GetLastError()) + "\n";
return 1;
}

Expand Down

0 comments on commit 5fa585d

Please sign in to comment.