From 8841513e7d3d6de3e31cef677b0e5516f4ae48cc Mon Sep 17 00:00:00 2001
From: Eric Cano <Eric.Cano@cern.ch>
Date: Wed, 2 Aug 2017 16:35:47 +0200
Subject: [PATCH] Fixed backtrace printout in ArchiveRequest::garbageCollect().

---
 objectstore/ArchiveRequest.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/objectstore/ArchiveRequest.cpp b/objectstore/ArchiveRequest.cpp
index 8265f75c82..fd781dacba 100644
--- a/objectstore/ArchiveRequest.cpp
+++ b/objectstore/ArchiveRequest.cpp
@@ -332,10 +332,12 @@ void ArchiveRequest::garbageCollect(const std::string &presumedOwner, AgentRefer
               .add("presumedOwner", presumedOwner)
               .add("copyNb", j->copynb());
         // Log differently depending on the exception type.
+        std::string backtrace = "";
         try {
           std::rethrow_exception(std::current_exception());
         } catch (cta::exception::Exception &ex) {
           params.add("exceptionMessage", ex.getMessageValue());
+          backtrace = ex.backtrace();
         } catch (std::exception & ex) {
           params.add("exceptionWhat", ex.what());
         } catch (...) {
@@ -344,8 +346,10 @@ void ArchiveRequest::garbageCollect(const std::string &presumedOwner, AgentRefer
         // This could be the end of the request, with various consequences.
         // This is handled here:
         if (finishIfNecessary()) {
-          lc.log(log::ERR, "In ArchiveRequest::garbageCollect(): failed to requeue the job. Failed it and removed the request as a consequence. Backtrace follows.");
-          lc.logBacktrace(log::ERR, "In ArchiveRequest::garbageCollect(): ");
+          std::string message="In ArchiveRequest::garbageCollect(): failed to requeue the job. Failed it and removed the request as a consequence.";
+          if (backtrace.size()) message += " Backtrace follows.";
+          lc.log(log::ERR, message);
+          if (backtrace.size()) lc.logBacktrace(log::ERR, backtrace);
           return;
         } else {
           commit();
-- 
GitLab