Skip to content

Commit

Permalink
Merge pull request #877 from solidify/feature/error-code
Browse files Browse the repository at this point in the history
Application returns error code 1 on error
  • Loading branch information
Alexander-Hjelm authored Oct 9, 2023
2 parents 349ce1d + f2be380 commit 999d83b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/WorkItemMigrator/JiraExport/JiraCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,27 @@ private void ConfigureCommandLineParserWithOptions()
commandLineApplication.OnExecute(() =>
{
bool forceFresh = forceOption.HasValue();
bool succeeded = true;

if (configOption.HasValue())
{
ExecuteMigration(userOption, passwordOption, urlOption, configOption, forceFresh, continueOnCriticalOption);
succeeded = ExecuteMigration(userOption, passwordOption, urlOption, configOption, forceFresh, continueOnCriticalOption);
}
else
{
commandLineApplication.ShowHelp();
}

return 0;
return succeeded ? 0 : 1;
});
}

private void ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical)
private bool ExecuteMigration(CommandOption user, CommandOption password, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical)
{
var itemsCount = 0;
var exportedItemsCount = 0;
var sw = new Stopwatch();
bool succeeded = true;
sw.Start();

try
Expand Down Expand Up @@ -137,15 +139,18 @@ private void ExecuteMigration(CommandOption user, CommandOption password, Comman
catch (CommandParsingException e)
{
Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}");
succeeded = false;
}
catch (Exception e)
{
Logger.Log(e, $"Unexpected migration error.");
succeeded = false;
}
finally
{
EndSession(itemsCount, sw);
}
return succeeded;
}

private static void InitSession(ConfigJson config, string continueOnCritical)
Expand Down
15 changes: 9 additions & 6 deletions src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@ private void ConfigureCommandLineParserWithOptions()
CommandOption forceOption = commandLineApplication.Option("--force", "Forces execution from start (instead of continuing from previous run)", CommandOptionType.NoValue);
CommandOption continueOnCriticalOption = commandLineApplication.Option("--continue", "Continue execution upon a critical error", CommandOptionType.SingleValue);


commandLineApplication.OnExecute(() =>
{
bool forceFresh = forceOption.HasValue();

bool succeeded = true;
if (configOption.HasValue())
{
ExecuteMigration(tokenOption, urlOption, configOption, forceFresh, continueOnCriticalOption);
succeeded = ExecuteMigration(tokenOption, urlOption, configOption, forceFresh, continueOnCriticalOption);
}
else
{
commandLineApplication.ShowHelp();
}

return 0;
return succeeded ? 0 : 1;
});
}

private void ExecuteMigration(CommandOption token, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical)
private bool ExecuteMigration(CommandOption token, CommandOption url, CommandOption configFile, bool forceFresh, CommandOption continueOnCritical)
{
ConfigJson config = null;
var itemCount = 0;
var revisionCount = 0;
var importedItems = 0;
var sw = new Stopwatch();
sw.Start();
bool succeeded = true;

try
{
Expand Down Expand Up @@ -101,7 +101,7 @@ private void ExecuteMigration(CommandOption token, CommandOption url, CommandOpt
if (agent == null)
{
Logger.Log(LogLevel.Critical, "Azure DevOps/TFS initialization error.");
return;
return false;
}

var executionBuilder = new ExecutionPlanBuilder(context);
Expand Down Expand Up @@ -169,15 +169,18 @@ private void ExecuteMigration(CommandOption token, CommandOption url, CommandOpt
catch (CommandParsingException e)
{
Logger.Log(LogLevel.Error, $"Invalid command line option(s): {e}");
succeeded = false;
}
catch (Exception e)
{
Logger.Log(e, $"Unexpected migration error.");
succeeded = false;
}
finally
{
EndSession(itemCount, revisionCount, sw);
}
return succeeded;
}

private static void BeginSession(string configFile, ConfigJson config, bool force, Agent agent, int itemsCount, int revisionCount)
Expand Down

0 comments on commit 999d83b

Please sign in to comment.