Skip to content

Commit

Permalink
ENH: Update NXRunner error messages to provide instructions for .json…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
imikejackson authored Aug 2, 2024
1 parent 24a870f commit 5aa8dd5
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/nxrunner/docs/NX_CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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`
78 changes: 63 additions & 15 deletions src/nxrunner/src/nxrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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)
{
Expand All @@ -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<nx::core::Pipeline> 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)
{
Expand All @@ -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));
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 5aa8dd5

Please sign in to comment.