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

Exception thrown when attempting to generate help text with custom IValidator present #440

Closed
adamsjdavid-work opened this issue Feb 19, 2021 · 4 comments
Labels
bug closed-duplicate This issue is closed because it is a duplicate of another issue.
Milestone

Comments

@adamsjdavid-work
Copy link

adamsjdavid-work commented Feb 19, 2021

When upgrading from V3.0 to V3.1, we experience test failures around the -h | --help flag. Namely, in our testing environment, running the help command is throwing an exception inside the McMaster Utility.

As part of our creation workflow, we have a custom implementation of IValidator called 'ExistingDirectoryOrTarFileValidator'.

private class ExistingDirectoryOrTarFileValidator : IValidator {[removed for brevity]}

It is added to an IValidationBuilder with the .Use(IValidator) method.

public static IValidationBuilder IfExistingFileThenHasTarExtension(this IValidationBuilder builder) { builder.Use(new ExistingDirectoryOrTarFileValidator()); return builder; }

This builder is used when creating a command option.

var inputOption = app.Option<string>( "-i|--input", "A directory, or a *.tar archive, containing all source files to be compiled.", CommandOptionType.MultipleValue) .IsRequired() .Accepts(p => p.ExistingFileOrDirectory() .IfExistingFileThenHasTarExtension());

Exception:

Unable to cast object of type 'ExistingDirectoryOrTarFileValidator' to type 'McMaster.Extensions.CommandLineUtils.Validation.AttributeValidator'.

Stack Trace:

at System.Linq.Enumerable.<CastIterator>d__63``1.MoveNext() in /_/src/System.Linq/src/System/Linq/Cast.cs:line 52 at McMaster.Extensions.CommandLineUtils.HelpText.DefaultHelpTextGenerator.GenerateOptions(CommandLineApplication application, TextWriter output, IReadOnlyList``1 visibleOptions, Int32 firstColumnWidth) at McMaster.Extensions.CommandLineUtils.HelpText.DefaultHelpTextGenerator.GenerateBody(CommandLineApplication application, TextWriter output) at McMaster.Extensions.CommandLineUtils.HelpText.DefaultHelpTextGenerator.Generate(CommandLineApplication application, TextWriter output) at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessOption(OptionArgument arg) at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.ProcessNext() at McMaster.Extensions.CommandLineUtils.CommandLineProcessor.Process() at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse(String[] args) at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<ExecuteAsync>d__157.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in /_/src/System.Private.CoreLib/shared/System/Runtime/ExceptionServices/ExceptionDispatchInfo.cs:line 63 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 180 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 151 at System.Runtime.CompilerServices.TaskAwaiter``1.GetResult() in /_/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/TaskAwaiter.cs:line 369 at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at [Removed for privacy].Program.Main(String[] args) in D:\repos\[removed for privacy]\Program.cs:line 255

This bug appears to have been introduced in #369.

@scott-xu
Copy link
Contributor

scott-xu commented Mar 7, 2021

I think it has been fixed by 042f4a9

@natemcmaster
Copy link
Owner

Can you try https://www.nuget.org/packages/McMaster.Extensions.CommandLineUtils/4.0.0-beta.74 and see if it fixes the issue?

@numbworks
Copy link

numbworks commented Aug 28, 2021

Hey,

first of all thank you for all the work that has been done to make this library available to us! :)

I had a similar issue with v3.1.0.
I installed 4.0.0-beta.74 and the problem is gone!

Thanks!

@natemcmaster
Copy link
Owner

Thanks for confirming it works.

@natemcmaster natemcmaster added the closed-duplicate This issue is closed because it is a duplicate of another issue. label Oct 13, 2021
@natemcmaster natemcmaster added this to the 4.0.0 milestone Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug closed-duplicate This issue is closed because it is a duplicate of another issue.
Projects
None yet
Development

No branches or pull requests

4 participants