From 5aa8dd5f2018cef08fae318a2adddd619104b417 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 2 Aug 2024 09:48:00 -0400 Subject: [PATCH] ENH: Update NXRunner error messages to provide instructions for .json files (#1032) - Also allow .d3dpipeline files to be sent through the --convert-output to provide a sanity check of the pipeline. Signed-off-by: Michael Jackson --- src/nxrunner/docs/NX_CLI.md | 6 +-- src/nxrunner/src/nxrunner.cpp | 78 ++++++++++++++++++++++++++++------- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/src/nxrunner/docs/NX_CLI.md b/src/nxrunner/docs/NX_CLI.md index 386b17f5a9..6d5b975c08 100644 --- a/src/nxrunner/docs/NX_CLI.md +++ b/src/nxrunner/docs/NX_CLI.md @@ -25,7 +25,7 @@ Lists available commands or displays details regarding a specific command. Executes the pipeline at the target filepath while printing the output to the terminal. Optionally, a log file is created at the specified filepath where the output is saved. -For example, ```--execute bash D:/Directory/pipeline.d3pipeline -l D:/Logs/pipeline.log``` will attempt to execute the pipeline at `D:/Directory/pipeline.d3pipeline` and saves the output to `D:/Logs/pipeline.log`. +For example, ```--execute D:/Directory/pipeline.d3pipeline -l D:/Logs/pipeline.log``` will attempt to execute the pipeline at `D:/Directory/pipeline.d3pipeline` and saves the output to `D:/Logs/pipeline.log`. ### Preflight @@ -36,7 +36,7 @@ For example, ```--execute bash D:/Directory/pipeline.d3pipeline -l D:/Logs/pipel Preflights the pipeline at the target filepath while printing the output to the terminal. Optionally, a log file is created at the specified filepath where the output is saved. -For example, ```--preflight bash D:/Directory/pipeline.d3pipeline -l D:/Logs/pipeline.log``` will attempt to preflight the pipeline at `D:/Directory/pipeline.d3pipeline` and saves the output to `D:/Logs/pipeline.log`. +For example, ```--preflight D:/Directory/pipeline.d3pipeline -l D:/Logs/pipeline.log``` will attempt to preflight the pipeline at `D:/Directory/pipeline.d3pipeline` and saves the output to `D:/Logs/pipeline.log`. ### Convert @@ -52,4 +52,4 @@ Converts a SIMPL pipeline at the target filepath to a simplnx pipeline. If any e The second option (convert-output / co) also saves the converted pipeline to file based on the name of the converted pipeline using the simplnx pipeline extension (`.d3pipeline`). -For example, ```--convert-output bash D:/Directory/SIMPL.json``` will attempt to convert the SIMPL pipeline at `D:/Directory/SIMPL.json` and save the converted pipeline to `D:/Directory/SIMPL.d3pipeline` +For example, ```--convert-output D:/Directory/SIMPL.json``` will attempt to convert the SIMPL pipeline at `D:/Directory/SIMPL.json` and save the converted pipeline to `D:/Directory/SIMPL.d3pipeline` diff --git a/src/nxrunner/src/nxrunner.cpp b/src/nxrunner/src/nxrunner.cpp index 690b535572..b85dde4178 100644 --- a/src/nxrunner/src/nxrunner.cpp +++ b/src/nxrunner/src/nxrunner.cpp @@ -304,10 +304,22 @@ Result<> ExecutePipeline(Pipeline& pipeline) Result<> ExecutePipeline(const Argument& arg) { std::string pipelinePath = arg.value; + cliOut << "Executing Pipeline: " << pipelinePath << "\n"; + auto loadPipelineResult = Pipeline::FromFile(pipelinePath); + + if(pipelinePath.ends_with(".json")) + { + cliOut << "Input file '" << pipelinePath << "' is a legacy DREAM.3D version 6.x formatted pipeline.\n"; + cliOut << " You will need to run `nxrunner --convert-output [PATH TO .JSON FILE]` to first convert the\n"; + cliOut << " pipeline file to the newer format. Please note that the conversion can fail as filters have\n"; + cliOut << " been updated and previous parameters may not be available in DREAM3D-NX.\n"; + return nx::core::ConvertResult(std::move(loadPipelineResult)); + } + if(loadPipelineResult.invalid()) { - cliOut << fmt::format("Could not load pipeline at path: '{}'", pipelinePath); + cliOut << fmt::format("Error: Could not load pipeline at path: '{}'", pipelinePath); cliOut.endline(); return nx::core::ConvertResult(std::move(loadPipelineResult)); } @@ -330,16 +342,27 @@ Result<> ExecutePipeline(const Argument& arg) Result<> PreflightPipeline(const Argument& arg) { std::string pipelinePath = arg.value; + cliOut << "Preflight Pipeline: " << pipelinePath << "\n"; auto loadPipelineResult = Pipeline::FromFile(pipelinePath); + + if(pipelinePath.ends_with(".json")) + { + cliOut << "Input file '" << pipelinePath << "' is a legacy DREAM.3D version 6.x formatted pipeline.\n"; + cliOut << " You will need to run `nxrunner --convert-output [PATH TO .JSON FILE]` to first convert the\n"; + cliOut << " pipeline file to the newer format. Please note that the conversion can fail as filters have\n"; + cliOut << " been updated and previous parameters may not be available in DREAM3D-NX.\n"; + return nx::core::ConvertResult(std::move(loadPipelineResult)); + } + if(loadPipelineResult.invalid()) { - cliOut << fmt::format("Could not load pipeline at path: '{}'", pipelinePath); + cliOut << fmt::format("Error: Could not load pipeline at path: '{}'", pipelinePath); cliOut.endline(); return nx::core::ConvertResult(std::move(loadPipelineResult)); } if(!loadPipelineResult.m_Warnings.empty()) { - cliOut << "Input Pipeline Warnings" + cliOut << "Preflight Pipeline: Input Pipeline Warnings" << "\n"; for(const auto& warning : loadPipelineResult.m_Warnings) { @@ -354,20 +377,41 @@ Result<> PreflightPipeline(const Argument& arg) return PreflightPipeline(pipeline); } -Result<> ConvertPipeline(const Argument& arg, bool saveConverted = false) +Result<> ConvertPipeline(const Argument& arg, bool printConvertedPipeline, bool saveConverted) { std::string pipelinePath = arg.value; - auto loadPipelineResult = Pipeline::FromSIMPLFile(pipelinePath); + cliOut << fmt::format("Input File: '{}'", pipelinePath); + cliOut.endline(); + + nx::core::Result loadPipelineResult; + if(pipelinePath.ends_with(".json")) + { + loadPipelineResult = Pipeline::FromSIMPLFile(pipelinePath); + } + else if(pipelinePath.ends_with(".d3dpipeline")) + { + cliOut << "Input file is already a DREAM3D-NX formatted pipeline file. A sanity check will be run instead. Any warnings will be printed\n"; + loadPipelineResult = nx::core::Pipeline::FromFile(pipelinePath, true); + saveConverted = false; + + for(const auto warning : loadPipelineResult.warnings()) + { + cliOut << fmt::format("Warning ({}): {}\n", warning.code, warning.message); + } + } + else + { + cliOut << "Error: Input file extension is not recognized. Aborting execution now.\n"; + return ConvertResult(std::move(loadPipelineResult)); + } + if(loadPipelineResult.invalid()) { - cliOut << fmt::format("Could not convert pipeline at path: '{}'", pipelinePath); + cliOut << fmt::format("Error: Could not convert pipeline at path: '{}'", pipelinePath); cliOut.endline(); return ConvertResult(std::move(loadPipelineResult)); } - cliOut << fmt::format("Converted SIMPL pipeline at path: '{}'\n", pipelinePath); - cliOut.endline(); - Pipeline pipeline = std::move(loadPipelineResult.value()); if(saveConverted) { @@ -380,12 +424,14 @@ Result<> ConvertPipeline(const Argument& arg, bool saveConverted = false) fout << pipeline.toJson().dump(4); fout.flush(); - cliOut << fmt::format("Saved converted pipeline at path: '{}'\n", pipelinePath); + cliOut << fmt::format("Converted File: '{}'", pipelinePath); + cliOut.endline(); + } + if(printConvertedPipeline) + { + cliOut << pipeline.toJson().dump(4); cliOut.endline(); } - - cliOut << pipeline.toJson().dump(4); - cliOut.endline(); return ConvertResult(std::move(loadPipelineResult)); } @@ -596,6 +642,7 @@ int main(int argc, char* argv[]) case ArgumentType::Execute: { try { + cliOut << "###### EXECUTE MODE ########\n"; auto result = ExecutePipeline(arguments[0]); results.push_back(result); } @@ -616,6 +663,7 @@ int main(int argc, char* argv[]) case ArgumentType::Preflight: { try { + cliOut << "###### PREFLIGHT MODE ########\n"; auto result = PreflightPipeline(arguments[0]); results.push_back(result); } @@ -634,12 +682,12 @@ int main(int argc, char* argv[]) break; } case ArgumentType::Convert: { - auto result = ConvertPipeline(arguments[0]); + auto result = ConvertPipeline(arguments[0], true, false); results.push_back(result); break; } case ArgumentType::ConvertOutput: { - auto result = ConvertPipeline(arguments[0], true); + auto result = ConvertPipeline(arguments[0], false, true); results.push_back(result); break; }