Skip to content
Snippets Groups Projects
Commit e4047b3f authored by Michael Davis's avatar Michael Davis
Browse files

[cta-admin] Handle user errors from CTA Frontend:

- XRootD/SSI/Protobuf errors or CTA Exceptions return error code 1
  (something went wrong with communication or in the frontend)

- User errors return error code 2 (user specified an invalid drive,
  vid, etc.)

- If text output, print error message on stderr and exit with code 2

- If --json output, print error message on stderr, print empty JSON
  array [] on stdout, and exit with code 2
parent 093954a8
No related branches found
No related tags found
No related merge requests found
......@@ -38,6 +38,16 @@ cta::admin::TextFormatter formattedText(1000);
namespace XrdSsiPb {
/*!
* User error exception
*/
class UserException : public std::runtime_error
{
public:
UserException(const std::string &err_msg) : std::runtime_error(err_msg) {}
};
/*!
* Alert callback.
*
......@@ -283,7 +293,7 @@ void CtaAdminCmd::send() const
isHeaderSent = true;
break;
case Response::RSP_ERR_PROTOBUF: throw XrdSsiPb::PbException(response.message_txt());
case Response::RSP_ERR_USER:
case Response::RSP_ERR_USER: throw XrdSsiPb::UserException(response.message_txt());
case Response::RSP_ERR_CTA: throw std::runtime_error(response.message_txt());
default: throw XrdSsiPb::PbException("Invalid response type.");
}
......@@ -490,6 +500,10 @@ int main(int argc, const char **argv)
std::cerr << "Error in Google Protocol Buffers: " << ex.what() << std::endl;
} catch (XrdSsiPb::XrdSsiException &ex) {
std::cerr << "Error from XRootD SSI Framework: " << ex.what() << std::endl;
} catch (XrdSsiPb::UserException &ex) {
if(CtaAdminCmd::isJson()) std::cout << CtaAdminCmd::jsonCloseDelim();
std::cerr << ex.what() << std::endl;
return 2;
} catch (std::runtime_error &ex) {
std::cerr << ex.what() << std::endl;
} catch (std::exception &ex) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment