add file open and write error handling

This commit is contained in:
Stephen Birarda 2016-03-11 11:04:34 -08:00
parent 7ccba8b406
commit 9522c2d17c
4 changed files with 25 additions and 7 deletions

View file

@ -61,13 +61,24 @@ void UploadAssetTask::run() {
if (file.exists()) {
qDebug() << "[WARNING] This file already exists: " << hexHash;
} else {
file.open(QIODevice::WriteOnly);
file.write(fileData);
replyPacket->writePrimitive(AssetServerError::NoError);
replyPacket->write(hash);
} else if (file.open(QIODevice::WriteOnly) && file.write(fileData) == qint64(fileSize)) {
file.close();
replyPacket->writePrimitive(AssetServerError::NoError);
replyPacket->write(hash);
} else {
// upload has failed - remove the file and return an error
auto removed = file.remove();
if (!removed) {
qWarning() << "Removal of failed upload file" << hash << "failed.";
}
replyPacket->writePrimitive(AssetServerError::FileOperationFailed);
}
replyPacket->writePrimitive(AssetServerError::NoError);
replyPacket->write(hash);
}
auto nodeList = DependencyManager::get<NodeList>();

View file

@ -42,6 +42,8 @@ QString AssetUpload::getErrorString() const {
return "The file could not be opened. Please check your permissions and try again.";
case AssetUpload::NetworkError:
return "There was a problem reaching your Asset Server. Please check your network connectivity.";
case AssetUpload::ServerFileError:
return "The Asset Server failed to store the asset. Please try again.";
default:
// not handled, do not show a message box
return QString();
@ -90,6 +92,9 @@ void AssetUpload::start() {
case AssetServerError::PermissionDenied:
_error = PermissionDenied;
break;
case AssetServerError::FileOperationFailed:
_error = ServerFileError;
break;
default:
_error = FileOpenError;
break;

View file

@ -32,7 +32,8 @@ public:
Timeout,
TooLarge,
PermissionDenied,
FileOpenError
FileOpenError,
ServerFileError
};
static const QString PERMISSION_DENIED_ERROR;

View file

@ -40,7 +40,8 @@ enum AssetServerError : uint8_t {
InvalidByteRange,
AssetTooLarge,
PermissionDenied,
MappingOperationFailed
MappingOperationFailed,
FileOperationFailed
};
enum AssetMappingOperationType : uint8_t {