From 5591dc229f1813dfdfe291835dfd4a116d83e45b Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Fri, 14 Aug 2020 05:57:53 -0500 Subject: [PATCH 1/2] CmdDiagnostics: Show per-file error messages. I had a broken symbolic link in my extensions directory. When I ran `timew diag` it would simply print on the screen: ``` stat error 2: No such file or directory ``` After this change, there is more context information about the source of the error: ``` timew 1.3.0 Platform: Linux Compiler: Version: 7.5.0 Caps: +stdc +stdc_hosted +LP64 +c8 +i32 +l64 +vp64 +time_t64 Compliance: C++11 Build Features Built: Aug 14 2020 05:57:06 Commit: 6fe15d26 CMake: 3.10.2 Build type: Debug Configuration TIMEWARRIORDB: - Cfg: /home/sruffell/.timewarrior/timewarrior.cfg (-rw- 0 bytes) Database: /home/sruffell/.timewarrior (drwx 4096 bytes) $EDITOR: vim Color theme: Built-in default 00 01 02 03 04 05 06 07 08 09 10 11 12 Extensions Location: /home/sruffell/.timewarrior/extensions (drwx 4096 bytes) /home/sruffell/.timewarrior/extensions/tsheet (stat error 2: No such file or directory) ``` Signed-off-by: Shaun Ruffell --- src/commands/CmdDiagnostics.cpp | 41 ++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/commands/CmdDiagnostics.cpp b/src/commands/CmdDiagnostics.cpp index 9ca1d55a..48ac1a49 100644 --- a/src/commands/CmdDiagnostics.cpp +++ b/src/commands/CmdDiagnostics.cpp @@ -37,26 +37,41 @@ //////////////////////////////////////////////////////////////////////////////// std::string describeFile (File& file) { - std::stringstream out; - out << file._data + try + { + std::stringstream out; + out << file._data << " (" << (file.is_link () - ? 'l' - : (file.is_directory () - ? 'd' - : '-')) + ? 'l' + : (file.is_directory () + ? 'd' + : '-')) << (file.readable () - ? 'r' - : '-') + ? 'r' + : '-') << (file.writable () - ? 'w' - : '-') + ? 'w' + : '-') << (file.executable () - ? 'x' - : '-') + ? 'x' + : '-') << " " << file.size () << " bytes)"; - return out.str (); + return out.str (); + } + catch (const std::string& error) + { + return file._data + " (" + error + ')'; + } + catch (const std::exception& error) + { + return file._data + " (" + error.what () + ')'; + } + catch (...) + { + return file._data + " (Unknown error)"; + } } //////////////////////////////////////////////////////////////////////////////// From eff3c36deb01f5301e64f68bd7d00b00fb723d77 Mon Sep 17 00:00:00 2001 From: Shaun Ruffell Date: Fri, 14 Aug 2020 06:32:19 -0500 Subject: [PATCH 2/2] CmdReport: Throw error if report fails to produce output Ideally this would be fixed in libshared. See GothenburgBitFactory/libshared#27 Signed-off-by: Shaun Ruffell --- src/commands/CmdReport.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/CmdReport.cpp b/src/commands/CmdReport.cpp index 4ff79292..aed158b6 100644 --- a/src/commands/CmdReport.cpp +++ b/src/commands/CmdReport.cpp @@ -109,7 +109,11 @@ int CmdReport ( // Run the extensions. std::vector output; - extensions.callExtension (script, split (input, '\n'), output); + int rc = extensions.callExtension (script, split (input, '\n'), output); + if (rc != 0 && output.size () == 0) + { + throw format ("'{1}' returned {2} without producing output.", script, rc); + } // Display the output. for (auto& line : output)