# HG changeset patch # User Sebastien Jodogne # Date 1445429455 -7200 # Node ID e1f5ab395297d867ca39d3d90976f794f4b562a5 # Parent 5cdea1cd2071e4670824564de03ce92cf2f8e48a PrintErrors diff -r 5cdea1cd2071 -r e1f5ab395297 OrthancServer/main.cpp --- a/OrthancServer/main.cpp Wed Oct 21 11:53:26 2015 +0200 +++ b/OrthancServer/main.cpp Wed Oct 21 14:10:55 2015 +0200 @@ -387,7 +387,7 @@ -static void PrintHelp(char* path) +static void PrintHelp(const char* path) { std::cout << "Usage: " << path << " [OPTION]... [CONFIGURATION]" << std::endl @@ -404,6 +404,7 @@ << " --logdir=[dir]\tdirectory where to store the log files" << std::endl << "\t\t\t(if not used, the logs are dumped to stderr)" << std::endl << " --config=[file]\tcreate a sample configuration file and exit" << std::endl + << " --errors\t\tprint the supported error codes and exit" << std::endl << " --verbose\t\tbe verbose in logs" << std::endl << " --trace\t\thighest verbosity in logs (for debug)" << std::endl << " --upgrade\t\tallow Orthanc to upgrade the version of the" << std::endl @@ -413,12 +414,16 @@ << std::endl << "Exit status:" << std::endl << " 0 if success," << std::endl +#if defined(_WIN32) + << "!= 0 if error (use the --errors option to get the list of possible errors)." << std::endl +#else << " -1 if error (have a look at the logs)." << std::endl +#endif << std::endl; } -static void PrintVersion(char* path) +static void PrintVersion(const char* path) { std::cout << path << " " << ORTHANC_VERSION << std::endl @@ -431,6 +436,32 @@ } +static void PrintErrorCode(ErrorCode code, const char* description) +{ + std::cout + << std::right << std::setw(16) + << static_cast(code) + << " " << description << std::endl; +} + + +static void PrintErrors(const char* path) +{ + std::cout + << path << " " << ORTHANC_VERSION << std::endl + << "Orthanc, lightweight, RESTful DICOM server for healthcare and medical research." << std::endl + << "List of error codes that could be returned by Orthanc:" << std::endl << std::endl; + + // The content of the following brackets is automatically generated + // by the "GenerateErrorCodes.py" script + { + PrintErrorCode(ErrorCode_BadFileFormat, "tutu"); + } + + std::cout << std::endl; +} + + static void LoadLuaScripts(ServerContext& context) { @@ -853,6 +884,11 @@ configurationFile = argv[i]; } } + else if (argument == "--errors") + { + PrintErrors(argv[0]); + return 0; + } else if (argument == "--help") { PrintHelp(argv[0]); @@ -937,8 +973,12 @@ } catch (const OrthancException& e) { - LOG(ERROR) << "Uncaught exception, stopping now: [" << e.What() << "]"; + LOG(ERROR) << "Uncaught exception, stopping now: [" << e.What() << "] (code " << e.GetErrorCode() << ")"; +#if defined(_WIN32) + status = static_cast(e.GetErrorCode()); +#else status = -1; +#endif } catch (const std::exception& e) { diff -r 5cdea1cd2071 -r e1f5ab395297 Resources/GenerateErrorCodes.py --- a/Resources/GenerateErrorCodes.py Wed Oct 21 11:53:26 2015 +0200 +++ b/Resources/GenerateErrorCodes.py Wed Oct 21 14:10:55 2015 +0200 @@ -141,3 +141,20 @@ with open(path, 'w') as f: f.write(a) + + + +## +## Generate the "PrintErrors" function in "main.cpp" +## + +path = os.path.join(BASE, 'OrthancServer', 'main.cpp') +with open(path, 'r') as f: + a = f.read() + +s = '\n'.join(map(lambda x: ' PrintError(%d, "%s");' % (x['Code'], x['Name']), ERRORS)) + +print s + +#with open(path, 'w') as f: +# f.write(a)