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 :
36 : /**
37 : * Unwind all causes linked to this exception
38 : *
39 : * @param ex the exception to process
40 : * @return a string
41 : */
42 0 : std::string const unwind ( ers::Issue const & exception )
43 : {
44 :
45 0 : if ( ers::Issue const * cause = exception.cause() )
46 : {
47 0 : std::stringstream s;
48 :
49 0 : while ( cause != nullptr )
50 : {
51 0 : s << cause->what() << "\n";
52 0 : cause = cause->cause();
53 : }
54 :
55 0 : return s.str();
56 0 : }
57 : else
58 : {
59 0 : return topcause ( exception );
60 : }
61 :
62 : }
63 :
64 : /**
65 : * Provide a string with the reason given by the exception
66 : *
67 : * @param ex is the exception to process
68 : * @return a string
69 : */
70 0 : std::string const reason ( ers::Issue const & exception )
71 : {
72 0 : return exception.what();
73 : }
74 :
75 : /**
76 : * Provide a string with the top level cause in this exception
77 : *
78 : * @param ex is the exception to process
79 : * @return a string
80 : */
81 0 : std::string const topcause ( ers::Issue const & exception )
82 : {
83 0 : if ( ers::Issue const * cause = exception.cause() )
84 : {
85 0 : return cause->what();
86 : }
87 : else
88 : {
89 0 : return exception.what();
90 : }
91 : }
92 :
93 : /**
94 : * Dump the exception caught at full detail level as specified by the environment
95 : * @param ex is the exception to process
96 : * @return a string
97 : */
98 0 : std::string const dump ( ers::Issue const & exception )
99 : {
100 0 : std::stringstream s;
101 0 : s << exception;
102 0 : return s.str();
103 0 : }
104 :
105 0 : std::string const parse ( ers::Issue const & exception )
106 : {
107 0 : return unwind ( exception );
108 : }
109 :
110 : //------------------------------------------------------------------------------------------
111 : }
112 : }
113 : }
114 : //------------------------------------------------------------------------------------------
115 :
|