Line data Source code
1 : // DUNE DAQ modification notice:
2 : // This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3 : // Fork baseline commit: dbe-02-12-17 (2022-05-12).
4 : // Renamed since fork: no.
5 :
6 : /*
7 : * config_api.cpp
8 : *
9 : * Created on: Nov 2, 2015
10 : * Author: Leonidas Georgopoulos
11 : */
12 :
13 : #include "dbe/Exceptions.hpp"
14 : #include "dbe/version.hpp"
15 : #include "dbe/config_api_version.hpp"
16 :
17 : #include "conffwk/Errors.hpp"
18 : #include "ers/Issue.hpp"
19 : #include <algorithm>
20 : #include <sstream>
21 : #include <string>
22 :
23 : char const * const dbe_lib_config_api_version = dbe_compiled_version;
24 :
25 : //------------------------------------------------------------------------------------------
26 : // DBE::CONFIG::ERRORS NAMESPACE
27 : //------------------------------------------------------------------------------------------
28 : namespace dbe
29 : {
30 : namespace config
31 : {
32 : namespace errors
33 : {
34 :
35 : namespace
36 : {
37 0 : inline std::string const trendl ( std::string s )
38 : {
39 0 : s.erase ( std::remove ( s.begin(), s.end(), '\n' ), s.end() );
40 0 : return s;
41 : }
42 : }
43 :
44 : /**
45 : * Unwind all causes linked to this exception
46 : *
47 : * @param ex the exception to process
48 : * @return a string
49 : */
50 0 : std::string const unwind ( ers::Issue const & exception )
51 : {
52 :
53 0 : if ( ers::Issue const * cause = exception.cause() )
54 : {
55 0 : std::stringstream s;
56 :
57 0 : while ( cause != nullptr )
58 : {
59 0 : s << trendl ( cause->what() ) << "\n";
60 0 : cause = cause->cause();
61 : }
62 :
63 0 : return s.str();
64 0 : }
65 : else
66 : {
67 0 : return topcause ( exception );
68 : }
69 :
70 : }
71 :
72 : /**
73 : * Provide a string with the reason given by the exception
74 : *
75 : * @param ex is the exception to process
76 : * @return a string
77 : */
78 0 : std::string const reason ( ers::Issue const & exception )
79 : {
80 0 : return exception.what();
81 : }
82 :
83 : /**
84 : * Provide a string with the top level cause in this exception
85 : *
86 : * @param ex is the exception to process
87 : * @return a string
88 : */
89 0 : std::string const topcause ( ers::Issue const & exception )
90 : {
91 0 : if ( ers::Issue const * cause = exception.cause() )
92 : {
93 0 : return cause->what();
94 : }
95 : else
96 : {
97 0 : return exception.what();
98 : }
99 : }
100 :
101 : /**
102 : * Dump the exception caught at full detail level as specified by the environment
103 : * @param ex is the exception to process
104 : * @return a string
105 : */
106 0 : std::string const dump ( ers::Issue const & exception )
107 : {
108 0 : std::stringstream s;
109 0 : s << exception;
110 0 : return s.str();
111 0 : }
112 :
113 0 : std::string const parse ( ers::Issue const & exception )
114 : {
115 0 : return unwind ( exception );
116 : }
117 :
118 : //------------------------------------------------------------------------------------------
119 : }
120 : }
121 : }
122 : //------------------------------------------------------------------------------------------
123 :
|