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 is thrown if type is placed in the Validation namespace #669

Closed
nZeus opened this issue Sep 24, 2024 · 5 comments
Closed

Exception is thrown if type is placed in the Validation namespace #669

nZeus opened this issue Sep 24, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@nZeus
Copy link

nZeus commented Sep 24, 2024

Describe the bug

This worked well before v5.0.0

Place your type inside the Validation folder:

using Vogen;

namespace Xxx.Validation;

[ValueObject<string>]
public partial record MyValueType {
	//...
}

This error is thrown from the generated class:
error CS0234: The type or namespace name 'Invalid' does not exist in the namespace Xxx.Validation' (are you missing an assembly reference?)`

I think it is related to this piece of code:

return new ValueObjectOrError<{{className}}>(Validation.Invalid("The value provided was null"));

Kind regards,
Ilia

Steps to reproduce

^

Expected behaviour

^

@nZeus nZeus added the bug Something isn't working label Sep 24, 2024
@TipluSebastian
Copy link

The code producing the bug seems to be the following:

public static ValueObjectOrError<MyValueObject> TryFrom(System.String value)
{
    if (value is null)
    {
        return new ValueObjectOrError<MyValueObject>(Validation.Invalid("The value provided was null"));
    }

    var validation = MyValueObject.Validate(value);
    if (validation != Vogen.Validation.Ok)
    {
        return new ValueObjectOrError<MyValueObject>(validation);
    }

    return new ValueObjectOrError<MyValueObject>(new MyValueObject(value));
}

Instead of Validation.Invalid("The value provided was null") it should be Vogen.Validation.Invalid("The value provided was null").

@SteveDunn
Copy link
Owner

Hi, thanks for the feedback @nZeus and @TipluSebastian . I'm just building a fix for this and will release a new version later today.

@AthenaAzuraeaX
Copy link

I think the bigger problem here is that Vogen relies on using directives. If anything conflicts with names in the Vogen namespace, than the generator will generate incorrect code. It would be best for the generator to use the full names of the types and not add the use Vogen directive at the top of the generated files.

@SteveDunn
Copy link
Owner

I think the bigger problem here is that Vogen relies on using directives. If anything conflicts with names in the Vogen namespace, than the generator will generate incorrect code. It would be best for the generator to use the full names of the types and not add the use Vogen directive at the top of the generated files.

That is a very good point! The next release won't have these in.

@SteveDunn
Copy link
Owner

Fixed in 5.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants