diff options
| author | Dan Engelbrecht <[email protected]> | 2026-03-14 10:56:43 +0100 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2026-03-14 14:19:08 +0100 |
| commit | f25d66892ddbc728588459326bd89f5a479c4eba (patch) | |
| tree | aff8b68ec0eb838c93f61470f2db4ee69f3f37f7 /src/zenserver | |
| parent | fix test (diff) | |
| download | zen-f25d66892ddbc728588459326bd89f5a479c4eba.tar.xz zen-f25d66892ddbc728588459326bd89f5a479c4eba.zip | |
exception guards in httpprojectstore
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/storage/projectstore/httpprojectstore.cpp | 154 |
1 files changed, 118 insertions, 36 deletions
diff --git a/src/zenserver/storage/projectstore/httpprojectstore.cpp b/src/zenserver/storage/projectstore/httpprojectstore.cpp index 2fa10a292..50ffae707 100644 --- a/src/zenserver/storage/projectstore/httpprojectstore.cpp +++ b/src/zenserver/storage/projectstore/httpprojectstore.cpp @@ -2872,27 +2872,68 @@ HttpProjectService::HandleRpcRequest(HttpRouterRequest& Req) WorkerThreadPool& NetworkWorkerPool = Workers->GetNetworkPool(); Context.ReportMessage(fmt::format("{}", Workers->GetWorkersInfo())); - RemoteProjectStore::Result Result = LoadOplog(LoadOplogContext{ - .ChunkStore = m_CidStore, - .RemoteStore = *RemoteStoreResult->Store, - .OptionalCache = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->Cache.get() : nullptr, - .CacheBuildId = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->BuildsId : Oid::Zero, - .OptionalCacheStats = RemoteStoreResult->OptionalCache ? &RemoteStoreResult->OptionalCache->Stats : nullptr, - .Oplog = *Oplog, - .NetworkWorkerPool = NetworkWorkerPool, - .WorkerPool = WorkerPool, - .ForceDownload = Force, - .IgnoreMissingAttachments = IgnoreMissingAttachments, - .CleanOplog = CleanOplog, - .PartialBlockRequestMode = PartialBlockRequestMode, - .PopulateCache = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->Populate : false, - .StoreLatencySec = RemoteStoreResult->LatencySec, - .StoreMaxRangeCountPerRequest = RemoteStoreResult->MaxRangeCountPerRequest, - .CacheLatencySec = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->LatencySec : -1.0, - .CacheMaxRangeCountPerRequest = - RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->MaxRangeCountPerRequest : 0, - .OptionalJobContext = &Context}); - auto Response = ConvertResult(Result); + RemoteProjectStore::Result Result; + try + { + Result = LoadOplog(LoadOplogContext{ + .ChunkStore = m_CidStore, + .RemoteStore = *RemoteStoreResult->Store, + .OptionalCache = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->Cache.get() : nullptr, + .CacheBuildId = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->BuildsId : Oid::Zero, + .OptionalCacheStats = RemoteStoreResult->OptionalCache ? &RemoteStoreResult->OptionalCache->Stats : nullptr, + .Oplog = *Oplog, + .NetworkWorkerPool = NetworkWorkerPool, + .WorkerPool = WorkerPool, + .ForceDownload = Force, + .IgnoreMissingAttachments = IgnoreMissingAttachments, + .CleanOplog = CleanOplog, + .PartialBlockRequestMode = PartialBlockRequestMode, + .PopulateCache = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->Populate : false, + .StoreLatencySec = RemoteStoreResult->LatencySec, + .StoreMaxRangeCountPerRequest = RemoteStoreResult->MaxRangeCountPerRequest, + .CacheLatencySec = RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->LatencySec : -1.0, + .CacheMaxRangeCountPerRequest = + RemoteStoreResult->OptionalCache ? RemoteStoreResult->OptionalCache->MaxRangeCountPerRequest : 0, + .OptionalJobContext = &Context}); + } + catch (const HttpClientError& HttpEx) + { + if (HttpEx.GetInternalErrorCode() != HttpClientErrorCode::kOK) + { + Result.ErrorCode = static_cast<int32_t>(HttpEx.GetInternalErrorCode()); + } + else + { + Result.ErrorCode = static_cast<int32_t>(HttpEx.GetHttpResponseCode() != HttpResponseCode::ImATeapot + ? static_cast<int>(HttpEx.GetHttpResponseCode()) + : 0); + } + Result.Reason = HttpEx.what(); + Result.Text = fmt::format("Failed due to an http exception (Err: {}, Code: {}): {}", + static_cast<int32_t>(HttpEx.GetInternalErrorCode()), + static_cast<int32_t>(HttpEx.GetHttpResponseCode()), + HttpEx.what()); + } + catch (const AssertException& AssertEx) + { + Result.ErrorCode = static_cast<int32_t>(HttpResponseCode::InternalServerError); + Result.Reason = AssertEx.what(); + Result.Text = fmt::format("Failed due to an assert exception: {}", AssertEx.FullDescription()); + } + catch (const std::system_error& SysEx) + { + Result.ErrorCode = static_cast<int32_t>(HttpResponseCode::InternalServerError); + Result.Reason = SysEx.what(); + Result.Text = fmt::format("Failed due to a system error ({}): {}", SysEx.code().value(), SysEx.what()); + } + catch (const std::exception& Ex) + { + Result.ErrorCode = static_cast<int32_t>(HttpResponseCode::InternalServerError); + Result.Reason = Ex.what(); + Result.Text = fmt::format("Failed due to an exception: {}", Ex.what()); + } + + auto Response = ConvertResult(Result); ZEN_INFO("LoadOplog: Status: {} '{}'", ToString(Response.first), Response.second); if (!IsHttpSuccessCode(Response.first)) { @@ -2961,21 +3002,62 @@ HttpProjectService::HandleRpcRequest(HttpRouterRequest& Req) WorkerThreadPool& WorkerPool = Workers->GetIOWorkerPool(); WorkerThreadPool& NetworkWorkerPool = Workers->GetNetworkPool(); - RemoteProjectStore::Result Result = SaveOplog(m_CidStore, - *ActualRemoteStore, - *Project, - *Oplog, - NetworkWorkerPool, - WorkerPool, - MaxBlockSize, - MaxChunksPerBlock, - MaxChunkEmbedSize, - ChunkFileSizeLimit, - EmbedLooseFile, - Force, - IgnoreMissingAttachments, - &Context); - auto Response = ConvertResult(Result); + RemoteProjectStore::Result Result; + try + { + Result = SaveOplog(m_CidStore, + *ActualRemoteStore, + *Project, + *Oplog, + NetworkWorkerPool, + WorkerPool, + MaxBlockSize, + MaxChunksPerBlock, + MaxChunkEmbedSize, + ChunkFileSizeLimit, + EmbedLooseFile, + Force, + IgnoreMissingAttachments, + &Context); + } + catch (const HttpClientError& HttpEx) + { + if (HttpEx.GetInternalErrorCode() != HttpClientErrorCode::kOK) + { + Result.ErrorCode = static_cast<int32_t>(HttpEx.GetInternalErrorCode()); + } + else + { + Result.ErrorCode = static_cast<int32_t>(HttpEx.GetHttpResponseCode() != HttpResponseCode::ImATeapot + ? static_cast<int>(HttpEx.GetHttpResponseCode()) + : 0); + } + Result.Reason = HttpEx.what(); + Result.Text = fmt::format("Failed due to an http exception (Err: {}, Code: {}): {}", + static_cast<int32_t>(HttpEx.GetInternalErrorCode()), + static_cast<int32_t>(HttpEx.GetHttpResponseCode()), + HttpEx.what()); + } + catch (const AssertException& AssertEx) + { + Result.ErrorCode = static_cast<int32_t>(HttpResponseCode::InternalServerError); + Result.Reason = AssertEx.what(); + Result.Text = fmt::format("Failed due to an assert exception: {}", AssertEx.FullDescription()); + } + catch (const std::system_error& SysEx) + { + Result.ErrorCode = static_cast<int32_t>(HttpResponseCode::InternalServerError); + Result.Reason = SysEx.what(); + Result.Text = fmt::format("Failed due to a system error ({}): {}", SysEx.code().value(), SysEx.what()); + } + catch (const std::exception& Ex) + { + Result.ErrorCode = static_cast<int32_t>(HttpResponseCode::InternalServerError); + Result.Reason = Ex.what(); + Result.Text = fmt::format("Failed due to an exception: {}", Ex.what()); + } + + auto Response = ConvertResult(Result); ZEN_INFO("SaveOplog: Status: {} '{}'", ToString(Response.first), Response.second); if (!IsHttpSuccessCode(Response.first)) { |