Skip to content

Commit

Permalink
Minor bug fixes for CLI tools
Browse files Browse the repository at this point in the history
It looks like I missed out on some CommandOptionType values. Additionally fixed a bug in ExistingFileAttribute, added some better logging, and we now print slightly nicer exceptions
  • Loading branch information
atruskie committed Feb 20, 2018
1 parent b098135 commit 1023979
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ public static T FindAndCheckAnalyser<T>(string analysisIdentifier, string partia
throw new ValidationException($"Cannot find an IAnalyser2 with the name `{searchName}`");
}

Log.Info($"Using analyzer {analyser.Identifier}");

return analyser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Arguments()
public string AnalysisIdentifier { get; set; }

[Option(
CommandOptionType.SingleValue,
Description = "A TEMP directory where cut files will be stored. Use this option for efficiency (e.g. write to a RAM Disk).",
ShortName = "t")]
[DirectoryExistsOrCreate(createIfNotExists: true)]
Expand Down
5 changes: 4 additions & 1 deletion src/AnalysisPrograms/ConcatenateIndexFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ public class Arguments : SubCommandBase

[Obsolete("Originally hack to get around powerargs limitation, can probably be removed soon")]
[Option(
CommandOptionType.SingleValue,
Description = "One directory where the original csv files are located. This option exists as an alternative to input data directories")]
public DirectoryInfo InputDataDirectory { get; set; }

[Option(Description = "Directory where the output is to go.")]
[Option(
CommandOptionType.SingleValue,
Description = "Directory where the output is to go.")]
[DirectoryExistsOrCreate(createIfNotExists: true)]
[LegalFilePath]
public DirectoryInfo OutputDirectory { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class Arguments
[LegalFilePath]
public override FileInfo Source { get; set; }

[Option(Description = "A TEMP directory where cut files will be stored. Use this option for efficiency (e.g. write to a RAM Disk).")]
[Option(
CommandOptionType.SingleValue,
Description = "A TEMP directory where cut files will be stored. Use this option for efficiency (e.g. write to a RAM Disk).")]
[DirectoryExistsOrCreate(createIfNotExists: true)]
[LegalFilePath]
public DirectoryInfo TempDir { get; set; }
Expand Down
19 changes: 12 additions & 7 deletions src/AnalysisPrograms/Production/MainEntryUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ private static void CurrentDomainOnUnhandledException(object sender, UnhandledEx
ExceptionLookup.ExceptionStyle style;
bool found = false;
Exception inner = ex;

// TODO: it looks like all exceptions will always be wrapped in a TargetInvocationException now so we always want to unwrap at least once
switch (ex)
{
case TargetInvocationException _:
Expand All @@ -270,13 +272,13 @@ private static void CurrentDomainOnUnhandledException(object sender, UnhandledEx
// if found, print message only if usage printing disabled
if (found && !style.PrintUsage)
{
// this branch prints the message but suppresses the stack trace in the console
// this branch prints the message, but the stack trace is only output in the log
NoConsole.Log.Fatal(FatalMessage, ex);
LoggedConsole.WriteFatalLine(FatalMessage + inner.Message);
}
else if (found && ex.GetType() != typeof(Exception))
{
// this branch prints the message, and command usage, but suppressed the stack trace in the console
// this branch prints the message, and command usage, but the stack trace is only output in the log
NoConsole.Log.Fatal(FatalMessage, ex);

var command = CommandLineApplication.Name;
Expand All @@ -286,15 +288,18 @@ private static void CurrentDomainOnUnhandledException(object sender, UnhandledEx
else
{
// otherwise its a unhandled exception, log and raise
Log.Fatal("Unhandled exception ->", ex);
// trying to print cleaner errors in console, so printing a full one to log, and the inner to the console
// this results in duplication in the log though
NoConsole.Log.Fatal("Unhandled exception ->\n", ex);
Log.Fatal("Unhandled exception ->\n", inner);

StringBuilder extraInformation = null;
PrintAggregateException(ex, ref extraInformation);

//if (extraInformation != null)
//{
// Log.Error(extraInformation.ToString());
//}
if (extraInformation != null)
{
Log.Error(extraInformation.ToString());
}
}

int returnCode = style?.ErrorCode ?? ExceptionLookup.SpecialExceptionErrorLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected override ValidationResult IsValid(object value, ValidationContext vali
return new ValidationResult(this.FormatErrorMessage(value as string));
}

if (Directory.Exists(path))
if (File.Exists(path))
{
if (!this.shouldExist)
{
Expand Down

0 comments on commit 1023979

Please sign in to comment.