# HG changeset patch # User František Kučera # Date 1558796451 -7200 # Node ID 4fdbe30d8c581a2728148ed797d0174419f9f9b0 # Parent 86d8bbc99e7b9680a0e451bd03491857d41859ce introduce AwkException diff -r 86d8bbc99e7b -r 4fdbe30d8c58 nbproject/configurations.xml --- a/nbproject/configurations.xml Sat May 25 11:36:31 2019 +0200 +++ b/nbproject/configurations.xml Sat May 25 17:00:51 2019 +0200 @@ -42,6 +42,7 @@ + AwkException.h relpipe-tr-awk.cpp @@ -92,6 +93,8 @@ true + + @@ -132,6 +135,8 @@ true + + diff -r 86d8bbc99e7b -r 4fdbe30d8c58 src/AwkException.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/AwkException.h Sat May 25 17:00:51 2019 +0200 @@ -0,0 +1,44 @@ +/** + * Relational pipes + * Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +using namespace std; + +namespace relpipe { +namespace tr { +namespace awk { + +class AwkException { +private: + wstring message; +public: + + AwkException(wstring message) : message(message) { + } + + wstring getMessge() { + return message; + } + +}; + +} +} +} \ No newline at end of file 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); diff -r 86d8bbc99e7b -r 4fdbe30d8c58 src/relpipe-tr-awk.cpp --- a/src/relpipe-tr-awk.cpp Sat May 25 11:36:31 2019 +0200 +++ b/src/relpipe-tr-awk.cpp Sat May 25 17:00:51 2019 +0200 @@ -63,6 +63,10 @@ fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessge().c_str()); fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); resultCode = e.getExitCode(); + } catch (AwkException& e) { + fwprintf(stderr, L"Caught AWK exception: %ls\n", e.getMessge().c_str()); + fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); + resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; } catch (RelpipeReaderException& e) { fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessge().c_str()); fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());