Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application returns error code 1 on error #877

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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