diff options
| author | Stefan Boberg <[email protected]> | 2021-10-20 13:01:03 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-20 13:01:03 +0200 |
| commit | a10c07cce7a889f5d6394d06d351f4a520c5836e (patch) | |
| tree | ece23014975fc14baed9194c1ee6b25ef427617a | |
| parent | Merge branch 'main' into gc (diff) | |
| download | zen-a10c07cce7a889f5d6394d06d351f4a520c5836e.tar.xz zen-a10c07cce7a889f5d6394d06d351f4a520c5836e.zip | |
zen: Improved error reporting for `print` command
| -rw-r--r-- | zen/cmds/print.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/zen/cmds/print.cpp b/zen/cmds/print.cpp index aac6afd44..1a73443dc 100644 --- a/zen/cmds/print.cpp +++ b/zen/cmds/print.cpp @@ -3,6 +3,7 @@ #include "print.h" #include <zencore/compactbinarypackage.h> +#include <zencore/compactbinaryvalidation.h> #include <zencore/filesystem.h> #include <zencore/logging.h> #include <zencore/string.h> @@ -40,9 +41,25 @@ PrintCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) if (m_Filename.empty()) throw std::runtime_error("No file specified"); - zen::FileContents Fc = zen::ReadFile(m_Filename); - IoBuffer Data = Fc.Flatten(); - zen::CbObject Object{SharedBuffer(Data)}; + zen::FileContents Fc = zen::ReadFile(m_Filename); + + if (Fc.ErrorCode) + { + zen::ConsoleLog().error("Failed to open file '{}': {}", m_Filename, Fc.ErrorCode.message()); + + return 1; + } + + IoBuffer Data = Fc.Flatten(); + + if (CbValidateError Result = ValidateCompactBinary(Data, CbValidateMode::All); Result != CbValidateError::None) + { + zen::ConsoleLog().error("Data in file '{}' does not appear to be compact binary (validation error {:#x})", m_Filename, Result); + + return 1; + } + + zen::CbObject Object{SharedBuffer(Data)}; zen::StringBuilder<1024> ObjStr; zen::CompactBinaryToJson(Object, ObjStr); |