diff -r 86d8bbc99e7b -r 4fdbe30d8c58 src/AwkHandler.h --- a/src/AwkHandler.h Sat May 25 11:36:31 2019 +0200 +++ b/src/AwkHandler.h Sat May 25 17:00:51 2019 +0200 @@ -41,6 +41,7 @@ #include #include "Configuration.h" +#include "AwkException.h" namespace relpipe { namespace tr { @@ -78,17 +79,17 @@ int result = pipe(fds); readerFD = fds[0]; writerFD = fds[1]; - if (result < 0) throw cli::RelpipeCLIException(L"Unable to create a pipe.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + if (result < 0) throw AwkException(L"Unable to create a pipe."); } void redirectFD(int oldfd, int newfd) { int result = dup2(oldfd, newfd); - if (result < 0) throw cli::RelpipeCLIException(L"Unable redirect FD.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + if (result < 0) throw AwkException(L"Unable redirect FD."); } void closeOrThrow(int fd) { int error = close(fd); - if (error) throw cli::RelpipeCLIException(L"Unable to close FD: " + to_wstring(fd) + L" from PID: " + to_wstring(getpid()), cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + if (error) throw AwkException(L"Unable to close FD: " + to_wstring(fd) + L" from PID: " + to_wstring(getpid())); } void execp(const std::vector& args) { @@ -99,7 +100,7 @@ execvp(a[0], (char*const*) a); delete[] a; - throw cli::RelpipeCLIException(L"Unable to do execvp().", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + throw AwkException(L"Unable to do execvp()."); } /* TODO: move to lib-cli when stable and used in other modules */ @@ -161,7 +162,7 @@ string_t a2v(const string_t& attributeName) { if (currenVariablesMapping.find(attributeName) != currenVariablesMapping.end()) return currenVariablesMapping[attributeName]; - else throw cli::RelpipeCLIException(L"Unable to find value in currenVariablesMapping", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + else throw AwkException(L"Unable to find value in currenVariablesMapping"); } template bool containsValue(std::map map, V value) { @@ -218,7 +219,7 @@ if (ch == 't') currentValue << L'\t'; else if (ch == 'n') currentValue << L'\n'; else if (ch == '\\') currentValue << L'\\'; - else throw cli::RelpipeCLIException(L"Unknown escape sequence. Only \\t, \\n and \\\\ are supported.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + else throw AwkException(L"Unknown escape sequence. Only \\t, \\n and \\\\ are supported."); } else { currentValue << ch; } @@ -288,7 +289,7 @@ __pid_t awkPid = fork(); if (awkPid < 0) { - throw cli::RelpipeCLIException(L"Unable to fork AWK process.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + throw AwkException(L"Unable to fork AWK process."); } else if (awkPid == 0) { // AWK child process closeOrThrow(awkInputWriterFD); @@ -379,7 +380,7 @@ __pid_t writerPid = fork(); if (writerPid < 0) { - throw cli::RelpipeCLIException(L"Unable to fork Writer process.", cli::CLI::EXIT_CODE_UNEXPECTED_ERROR); // TODO: better exceptions? + throw AwkException(L"Unable to fork Writer process."); } else if (writerPid == 0) { // Writer child process closeOrThrow(awkInputWriterFD);