diff options
| author | Dan Engelbrecht <[email protected]> | 2024-04-04 14:32:40 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-04-04 14:32:40 +0200 |
| commit | 12b7bf1c16f671c83840961c37a339141a7ffbb3 (patch) | |
| tree | 3c503e6e1cd4d53b87c1baebcf9286ca8b72db06 /src/zenserver | |
| parent | hardening parsepackagemessage (#38) (diff) | |
| download | zen-12b7bf1c16f671c83840961c37a339141a7ffbb3.tar.xz zen-12b7bf1c16f671c83840961c37a339141a7ffbb3.zip | |
improved assert (#37)
- Improvement: Add file and line to ASSERT exceptions
- Improvement: Catch call stack when throwing assert exceptions and log/output call stack at important places to provide more context to caller
Diffstat (limited to 'src/zenserver')
| -rw-r--r-- | src/zenserver/admin/admin.cpp | 4 | ||||
| -rw-r--r-- | src/zenserver/config.cpp | 6 | ||||
| -rw-r--r-- | src/zenserver/config/luaconfig.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/diag/diagsvcs.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/main.cpp | 14 | ||||
| -rw-r--r-- | src/zenserver/projectstore/fileremoteprojectstore.cpp | 4 | ||||
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 10 | ||||
| -rw-r--r-- | src/zenserver/projectstore/remoteprojectstore.cpp | 6 | ||||
| -rw-r--r-- | src/zenserver/sentryintegration.cpp | 17 | ||||
| -rw-r--r-- | src/zenserver/upstream/upstreamcache.cpp | 20 | ||||
| -rw-r--r-- | src/zenserver/vfs/vfsimpl.cpp | 2 | ||||
| -rw-r--r-- | src/zenserver/vfs/vfsservice.cpp | 4 | ||||
| -rw-r--r-- | src/zenserver/zenserver.cpp | 4 |
13 files changed, 46 insertions, 49 deletions
diff --git a/src/zenserver/admin/admin.cpp b/src/zenserver/admin/admin.cpp index 8093a0735..75ff03912 100644 --- a/src/zenserver/admin/admin.cpp +++ b/src/zenserver/admin/admin.cpp @@ -603,7 +603,7 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, EmitStats("cas", Stats.CasStats); EmitStats("project", Stats.ProjectStats); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("exception in disk stats gathering for '{}': {}", m_ServerOptions.DataDir, Ex.what()); } @@ -622,7 +622,7 @@ HttpAdminService::HttpAdminService(GcScheduler& Scheduler, Obj.EndArray(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("exception in state gathering for '{}': {}", m_ServerOptions.SystemRootDir, Ex.what()); } diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 00581d758..aa0eedb0e 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -128,7 +128,7 @@ ReadAllCentralManifests(const std::filesystem::path& SystemRoot) ZEN_WARN("failed to load manifest '{}': {}", File, ToString(ValidateError)); } } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("failed to load manifest '{}': {}", File, Ex.what()); } @@ -1004,7 +1004,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) { Result = options.parse(argc, argv); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { throw zen::OptionParseException(Ex.what()); } @@ -1069,7 +1069,7 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) ValidateOptions(ServerOptions); } - catch (zen::OptionParseException& e) + catch (const zen::OptionParseException& e) { ZEN_CONSOLE_ERROR("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help()); diff --git a/src/zenserver/config/luaconfig.cpp b/src/zenserver/config/luaconfig.cpp index cdc808cf6..f742fa34a 100644 --- a/src/zenserver/config/luaconfig.cpp +++ b/src/zenserver/config/luaconfig.cpp @@ -280,7 +280,7 @@ Options::Parse(const std::filesystem::path& Path, const cxxopts::ParseResult& Cm config(); } - catch (std::exception& e) + catch (const std::exception& e) { throw std::runtime_error(fmt::format("failed to load config script ('{}'): {}", Path, e.what()).c_str()); } diff --git a/src/zenserver/diag/diagsvcs.cpp b/src/zenserver/diag/diagsvcs.cpp index 1a10782e9..f0aec98ab 100644 --- a/src/zenserver/diag/diagsvcs.cpp +++ b/src/zenserver/diag/diagsvcs.cpp @@ -36,7 +36,7 @@ ReadLogFile(const std::string& Path, StringBuilderBase& Out) return true; } - catch (std::exception&) + catch (const std::exception&) { Out.Reset(); return false; diff --git a/src/zenserver/main.cpp b/src/zenserver/main.cpp index 7a6d2dd22..6b31dc82e 100644 --- a/src/zenserver/main.cpp +++ b/src/zenserver/main.cpp @@ -247,7 +247,12 @@ ZenEntryPoint::Run() Server.Run(); } - catch (std::exception& e) + catch (const AssertException& AssertEx) + { + ZEN_CRITICAL("Caught assert exception in main for process {}: {}", zen::GetCurrentProcessId(), AssertEx.FullDescription()); + RequestApplicationExit(1); + } + catch (const std::exception& e) { ZEN_CRITICAL("Caught exception in main for process {}: {}", zen::GetCurrentProcessId(), e.what()); RequestApplicationExit(1); @@ -407,7 +412,12 @@ main(int argc, char* argv[]) return App.Run(); #endif } - catch (std::exception& Ex) + catch (const AssertException& AssertEx) + { + fprintf(stderr, "ERROR: Caught assert exception in main: '%s'", AssertEx.FullDescription().c_str()); + return 1; + } + catch (const std::exception& Ex) { fprintf(stderr, "ERROR: Caught exception in main: '%s'", Ex.what()); diff --git a/src/zenserver/projectstore/fileremoteprojectstore.cpp b/src/zenserver/projectstore/fileremoteprojectstore.cpp index 4248bbf2a..764bea355 100644 --- a/src/zenserver/projectstore/fileremoteprojectstore.cpp +++ b/src/zenserver/projectstore/fileremoteprojectstore.cpp @@ -79,7 +79,7 @@ public: } Result.RawHash = IoHash::HashBuffer(Payload); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { Result.ErrorCode = gsl::narrow<int32_t>(HttpResponseCode::InternalServerError); Result.Reason = fmt::format("Failed saving oplog container to '{}'. Reason: {}", ContainerPath, Ex.what()); @@ -108,7 +108,7 @@ public: Offset += Segment.GetSize(); } } - catch (std::exception& Ex) + catch (const std::exception& Ex) { Result.ErrorCode = gsl::narrow<int32_t>(HttpResponseCode::InternalServerError); Result.Reason = fmt::format("Failed saving oplog attachment to '{}'. Reason: {}", ChunkPath, Ex.what()); diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index 0109533f6..84ed6f842 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -1679,7 +1679,7 @@ ProjectStore::Project::WriteAccessTimes() WriteFile(ProjectAccessTimesFilePath, Data.GetBuffer().AsIoBuffer()); } - catch (std::exception& Err) + catch (const std::exception& Err) { ZEN_WARN("writing access times FAILED, reason: '{}'", Err.what()); } @@ -1714,7 +1714,7 @@ ProjectStore::Project::NewOplog(std::string_view OplogId, const std::filesystem: Log->Write(); return Log; } - catch (std::exception&) + catch (const std::exception&) { // In case of failure we need to ensure there's no half constructed entry around // @@ -1760,7 +1760,7 @@ ProjectStore::Project::OpenOplog(std::string_view OplogId) return Log; } - catch (std::exception& ex) + catch (const std::exception& ex) { ZEN_WARN("failed to open oplog '{}' @ '{}': {}", OplogId, OplogBasePath, ex.what()); @@ -2371,7 +2371,7 @@ ProjectStore::OpenProject(std::string_view ProjectId) Prj->Read(); return Prj; } - catch (std::exception& e) + catch (const std::exception& e) { ZEN_WARN("failed to open {} @ {} ({})", ProjectId, BasePath, e.what()); m_Projects.erase(std::string{ProjectId}); @@ -4017,7 +4017,7 @@ ProjectStore::CreateReferenceCheckers(GcCtx& Ctx) } } } - catch (std::exception&) + catch (const std::exception&) { while (!Checkers.empty()) { diff --git a/src/zenserver/projectstore/remoteprojectstore.cpp b/src/zenserver/projectstore/remoteprojectstore.cpp index e11541534..8efb92e6b 100644 --- a/src/zenserver/projectstore/remoteprojectstore.cpp +++ b/src/zenserver/projectstore/remoteprojectstore.cpp @@ -835,7 +835,7 @@ BuildContainer(CidStore& ChunkStore, } } } - catch (std::exception& Ex) + catch (const std::exception& Ex) { RemoteResult.SetError(gsl::narrow<int>(HttpResponseCode::NotFound), fmt::format("Failed to resolve attachment {}", RawHash), @@ -1216,7 +1216,7 @@ BuildContainer(CidStore& ChunkStore, return {}; } } - catch (std::exception& Ex) + catch (const std::exception& Ex) { BlockCreateLatch.CountDown(); while (!BlockCreateLatch.Wait(1000)) @@ -1740,7 +1740,7 @@ SaveOplog(CidStore& ChunkStore, CreatedBlocks.insert({BlockHash, std::move(BlockBuffer)}); ZEN_DEBUG("Saved temp block to '{}', {}", AttachmentTempPath, NiceBytes(BlockBuffer.GetSize())); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { RemoteResult.SetError(gsl::narrow<int32_t>(HttpResponseCode::InternalServerError), Ex.what(), diff --git a/src/zenserver/sentryintegration.cpp b/src/zenserver/sentryintegration.cpp index 11bf78a75..a8d967985 100644 --- a/src/zenserver/sentryintegration.cpp +++ b/src/zenserver/sentryintegration.cpp @@ -31,13 +31,10 @@ namespace sentry { struct SentryAssertImpl : zen::AssertImpl { - ZEN_FORCENOINLINE ZEN_DEBUG_SECTION SentryAssertImpl(); - virtual ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ~SentryAssertImpl(); virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename, int LineNumber, const char* FunctionName, const char* Msg) override; - AssertImpl* PrevAssertImpl; }; class sentry_sink final : public spdlog::sinks::base_sink<spdlog::details::null_mutex> @@ -85,7 +82,7 @@ sentry_sink::sink_it_(const spdlog::details::log_msg& msg) sentry_event_value_add_stacktrace(event, NULL, 0); sentry_capture_event(event); } - catch (std::exception&) + catch (const std::exception&) { // If our logging with Message formatting fails we do a non-allocating version and just post the msg.payload raw char TmpBuffer[256]; @@ -105,16 +102,6 @@ sentry_sink::flush_() { } -SentryAssertImpl::SentryAssertImpl() : PrevAssertImpl(CurrentAssertImpl) -{ - CurrentAssertImpl = this; -} - -SentryAssertImpl::~SentryAssertImpl() -{ - CurrentAssertImpl = PrevAssertImpl; -} - void SentryAssertImpl::OnAssert(const char* Filename, int LineNumber, const char* FunctionName, const char* Msg) { @@ -128,7 +115,7 @@ SentryAssertImpl::OnAssert(const char* Filename, int LineNumber, const char* Fun sentry_event_value_add_stacktrace(event, NULL, 0); sentry_capture_event(event); } - catch (std::exception&) + catch (const std::exception&) { // If our logging with Message formatting fails we do a non-allocating version and just post the Msg raw sentry_value_t event = sentry_value_new_message_event( diff --git a/src/zenserver/upstream/upstreamcache.cpp b/src/zenserver/upstream/upstreamcache.cpp index dac29c273..6d1d026cc 100644 --- a/src/zenserver/upstream/upstreamcache.cpp +++ b/src/zenserver/upstream/upstreamcache.cpp @@ -152,7 +152,7 @@ namespace detail { return m_Status.EndpointStatus(); } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -292,7 +292,7 @@ namespace detail { return {.Status = {.Error{.ErrorCode = Result.ErrorCode, .Reason = std::move(Result.Reason)}}}; } } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -388,7 +388,7 @@ namespace detail { return {.Status = {.Error{.ErrorCode = Result.ErrorCode, .Reason = std::move(Result.Reason)}}}; } } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -615,7 +615,7 @@ namespace detail { }); } } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -825,7 +825,7 @@ namespace detail { return m_Status.EndpointStatus(); } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -861,7 +861,7 @@ namespace detail { return {.Status = {.Error{.ErrorCode = Result.ErrorCode, .Reason = std::move(Result.Reason)}}}; } } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -984,7 +984,7 @@ namespace detail { return {.Status = {.Error{.ErrorCode = Result.ErrorCode, .Reason = std::move(Result.Reason)}}}; } } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -1405,7 +1405,7 @@ namespace detail { .ElapsedSeconds = TotalElapsedSeconds, .Success = Result.Success}; } - catch (std::exception& Err) + catch (const std::exception& Err) { m_Status.Set(UpstreamEndpointState::kError, Err.what()); @@ -1980,7 +1980,7 @@ private: { ProcessCacheRecord(std::move(CacheRecord)); } - catch (std::exception& Err) + catch (const std::exception& Err) { ZEN_ERROR("upload cache record '{}/{}/{}' FAILED, reason '{}'", CacheRecord.Namespace, @@ -2052,7 +2052,7 @@ private: } } } - catch (std::exception& Err) + catch (const std::exception& Err) { ZEN_ERROR("check endpoint(s) health FAILED, reason '{}'", Err.what()); } diff --git a/src/zenserver/vfs/vfsimpl.cpp b/src/zenserver/vfs/vfsimpl.cpp index 5ef89ee77..5c9f32c69 100644 --- a/src/zenserver/vfs/vfsimpl.cpp +++ b/src/zenserver/vfs/vfsimpl.cpp @@ -238,7 +238,7 @@ VfsService::Impl::VfsThread() m_VfsThreadRunning.Set(); m_VfsHost->Run(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("exception caught in VFS thread: {}", Ex.what()); diff --git a/src/zenserver/vfs/vfsservice.cpp b/src/zenserver/vfs/vfsservice.cpp index 04ba29ed2..d302a10ec 100644 --- a/src/zenserver/vfs/vfsservice.cpp +++ b/src/zenserver/vfs/vfsservice.cpp @@ -105,7 +105,7 @@ VfsService::VfsService() { m_Impl->Mount(Mountpath); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { return Req.ServerRequest().WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, Ex.what()); } @@ -123,7 +123,7 @@ VfsService::VfsService() { m_Impl->Unmount(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { return Req.ServerRequest().WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, Ex.what()); } diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp index d1faeb8b6..e6e451952 100644 --- a/src/zenserver/zenserver.cpp +++ b/src/zenserver/zenserver.cpp @@ -761,7 +761,7 @@ ZenServer::Cleanup() m_Http = {}; m_JobQueue.reset(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_ERROR("exception thrown during Cleanup() in {}: '{}'", ZEN_APP_NAME, Ex.what()); } @@ -831,7 +831,7 @@ ZenServer::CheckStateMarker() return; } } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("state marker at {} could not be checked, reason: '{}'", StateMarkerPath, Ex.what()); RequestExit(1); |