XRootD
XrdClStatus.cc
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #include "XrdCl/XrdClStatus.hh"
20 #include "XrdSys/XrdSysE2T.hh"
21 #include "XProtocol/XProtocol.hh"
22 #include <cstring>
23 
24 namespace
25 {
26  using namespace XrdCl;
27  struct ErrorMap
28  {
29  uint16_t code;
30  const char *msg;
31  };
32 
33  ErrorMap errors[] = {
34  { errUnknown, "Unknown error" },
35  { errInvalidOp, "Invalid operation" },
36  { errFcntl, "Fcntl error" },
37  { errPoll, "Poll error" },
38  { errConfig, "Configuration error" },
39  { errInternal, "Internal error" },
40  { errUnknownCommand, "Command not found" },
41  { errInvalidArgs, "Invalid arguments" },
42  { errInProgress, "Operation in progress" },
43  { errUninitialized, "Initialization error" },
44  { errOSError, "OS Error" },
45  { errNotSupported, "Operation not supported" },
46  { errDataError, "Received corrupted data" },
47  { errNotImplemented, "Operation is not implemented" },
48  { errNoMoreReplicas, "No more replicas to try" },
49  { errPipelineFailed, "Pipeline failed" },
50  { errInvalidAddr, "Invalid address" },
51  { errSocketError, "Socket error" },
52  { errSocketTimeout, "Socket timeout" },
53  { errSocketDisconnected, "Socket disconnected" },
54  { errPollerError, "Poller error" },
55  { errSocketOptError, "Socket opt error" },
56  { errStreamDisconnect, "Stream disconnect" },
57  { errConnectionError, "Connection error" },
58  { errInvalidSession, "Invalid session" },
59  { errTlsError, "TLS error" },
60  { errInvalidMessage, "Invalid message" },
61  { errNotFound, "Resource not found" },
62  { errCheckSumError, "CheckSum error" },
63  { errRedirectLimit, "Redirect limit has been reached" },
64  { errHandShakeFailed, "Hand shake failed" },
65  { errLoginFailed, "Login failed" },
66  { errAuthFailed, "Auth failed" },
67  { errQueryNotSupported, "Query not supported" },
68  { errOperationExpired, "Operation expired" },
69  { errOperationInterrupted, "Operation interrupted" },
70  { errThresholdExceeded, "Threshold exceeded" },
71  { errNoMoreFreeSIDs, "No more free SIDs" },
72  { errInvalidRedirectURL, "Invalid redirect URL" },
73  { errInvalidResponse, "Invalid response" },
74  { errRedirect, "Unhandled redirect" },
75  { errErrorResponse, "Error response" },
76  { errLocalError, "Local error" },
77  { errResponseNegative, "Query response negative" },
78  { 0, 0 } };
79 
80  //----------------------------------------------------------------------------
81  // Get error code
82  //----------------------------------------------------------------------------
83  std::string GetErrorMessage( uint16_t code )
84  {
85  for( int i = 0; errors[i].msg != 0; ++i )
86  if( errors[i].code == code )
87  return errors[i].msg;
88  return "Unknown error code";
89  }
90 }
91 
92 namespace XrdCl
93 {
94  //----------------------------------------------------------------------------
95  // Create a string representation
96  //----------------------------------------------------------------------------
97  std::string Status::ToString() const
98  {
99  std::ostringstream o;
100 
101  //--------------------------------------------------------------------------
102  // The status is OK
103  //--------------------------------------------------------------------------
104  if( IsOK() )
105  {
106  o << "[SUCCESS] ";
107 
108  if( code == suContinue )
109  o << "Continue";
110  else if( code == suRetry )
111  o << "Retry";
112 
113  return o.str();
114  }
115 
116  //--------------------------------------------------------------------------
117  // We have an error
118  //--------------------------------------------------------------------------
119  if( IsFatal() )
120  o << "[FATAL] ";
121  else
122  o << "[ERROR] ";
123 
124  o << GetErrorMessage( code );
125 
126  //--------------------------------------------------------------------------
127  // Add errno
128  //--------------------------------------------------------------------------
129  if( errNo >= kXR_ArgInvalid ) // kXR_ArgInvalid is the first (lowest) xrootd error code
130  // it is used in an inconsistent way sometimes it is
131  // xrootd error code and sometimes it is a plain errno
132  o << ": " << XrdSysE2T( XProtocol::toErrno( errNo ) );
133  else if ( errNo )
134  o << ": " << XrdSysE2T( errNo );
135 
136  return o.str();
137  }
138 }
@ kXR_ArgInvalid
Definition: XProtocol.hh:990
const char * XrdSysE2T(int errcode)
Definition: XrdSysE2T.cc:104
static int toErrno(int xerr)
Definition: XProtocol.hh:1408
const uint16_t errPoll
error while polling descriptors
Definition: XrdClStatus.hh:54
const uint16_t errUnknown
Unknown error.
Definition: XrdClStatus.hh:50
const uint16_t suRetry
Definition: XrdClStatus.hh:40
const uint16_t errQueryNotSupported
Definition: XrdClStatus.hh:89
const uint16_t errInvalidAddr
Definition: XrdClStatus.hh:71
const uint16_t errStreamDisconnect
Definition: XrdClStatus.hh:77
const uint16_t errRedirectLimit
Definition: XrdClStatus.hh:102
const uint16_t errUninitialized
Definition: XrdClStatus.hh:60
const uint16_t errSocketOptError
Definition: XrdClStatus.hh:76
const uint16_t errErrorResponse
Definition: XrdClStatus.hh:105
const uint16_t errTlsError
Definition: XrdClStatus.hh:80
const uint16_t errOperationExpired
Definition: XrdClStatus.hh:90
const uint16_t errNotImplemented
Operation is not implemented.
Definition: XrdClStatus.hh:64
const uint16_t errPollerError
Definition: XrdClStatus.hh:75
const uint16_t errUnknownCommand
Definition: XrdClStatus.hh:57
const uint16_t errResponseNegative
Query response was negative.
Definition: XrdClStatus.hh:109
const uint16_t errLoginFailed
Definition: XrdClStatus.hh:87
const uint16_t errNoMoreFreeSIDs
Definition: XrdClStatus.hh:97
const uint16_t errInProgress
Definition: XrdClStatus.hh:59
const uint16_t errNotFound
Definition: XrdClStatus.hh:100
const uint16_t errSocketTimeout
Definition: XrdClStatus.hh:73
const uint16_t errDataError
data is corrupted
Definition: XrdClStatus.hh:63
const uint16_t errInternal
Internal error.
Definition: XrdClStatus.hh:56
const uint16_t errInvalidOp
Definition: XrdClStatus.hh:51
const uint16_t errHandShakeFailed
Definition: XrdClStatus.hh:86
const uint16_t errConfig
System misconfigured.
Definition: XrdClStatus.hh:55
const uint16_t errOSError
Definition: XrdClStatus.hh:61
const uint16_t errPipelineFailed
Pipeline failed and operation couldn't be executed.
Definition: XrdClStatus.hh:66
const uint16_t errInvalidResponse
Definition: XrdClStatus.hh:99
const uint16_t errInvalidArgs
Definition: XrdClStatus.hh:58
const uint16_t errInvalidRedirectURL
Definition: XrdClStatus.hh:98
const uint16_t errConnectionError
Definition: XrdClStatus.hh:78
const uint16_t errNotSupported
Definition: XrdClStatus.hh:62
const uint16_t errLocalError
Definition: XrdClStatus.hh:107
const uint16_t errSocketError
Definition: XrdClStatus.hh:72
const uint16_t errCheckSumError
Definition: XrdClStatus.hh:101
const uint16_t errThresholdExceeded
Definition: XrdClStatus.hh:92
const uint16_t errOperationInterrupted
Definition: XrdClStatus.hh:91
const uint16_t suContinue
Definition: XrdClStatus.hh:39
const uint16_t errFcntl
failed manipulate file descriptor
Definition: XrdClStatus.hh:53
const uint16_t errNoMoreReplicas
No more replicas to try.
Definition: XrdClStatus.hh:65
const uint16_t errInvalidSession
Definition: XrdClStatus.hh:79
const uint16_t errRedirect
Definition: XrdClStatus.hh:106
const uint16_t errSocketDisconnected
Definition: XrdClStatus.hh:74
const uint16_t errAuthFailed
Definition: XrdClStatus.hh:88
const uint16_t errInvalidMessage
Definition: XrdClStatus.hh:85
uint16_t code
Error type, or additional hints on what to do.
Definition: XrdClStatus.hh:147
bool IsOK() const
We're fine.
Definition: XrdClStatus.hh:124
bool IsFatal() const
Fatal error.
Definition: XrdClStatus.hh:123
std::string ToString() const
Create a string representation.
Definition: XrdClStatus.cc:97
uint32_t errNo
Errno, if any.
Definition: XrdClStatus.hh:148