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

Improvement suggestion: Error message when Embeddable has a missing field #3254

Open
Nahuel92 opened this issue Nov 29, 2024 · 0 comments
Open

Comments

@Nahuel92
Copy link

Issue description

Hi there!

I would like to suggest an improvement on how Micronaut Data handles error messages for the following use case.

When using a validated @Embeddable , if:

  • It has a mandatory field
  • The result set has a null value for that field

The error message is a bit confusing, as it says that the whole @Embeddable is null/missing. Take for example these data models:

@MappedEntity("my_entity")
public record MyEntity(
        @MappedProperty("id") @Id @GeneratedValue @Nullable Long id,
        @Relation(Relation.Kind.EMBEDDED) @Valid @NotNull AuditFields auditFields) {
}

@Embeddable
public record AuditFields(
        @MappedProperty("created_on") @NotNull LocalDate createdOn,
        @MappedProperty("created_by") @NotBlank String createdBy) {
}

If the DB has a missing/null createdBy field, for instance, this is the error message throw by the repository:

Error instantiating entity [io.github.nahuel92.MyEntity]: Null argument specified for [auditFields]. If this argument is allowed to be null annotate it with @Nullable

This can be improved by making the error message something like this:

Error instantiating entity [io.github.nahuel92.MyEntity]: Null argument specified for [auditFields.createdBy]. If this argument is allowed to be null annotate it with @Nullable

Here's an example app where you can see this in action:

https://github.com/Nahuel92/poc-projects/tree/master/micronaut/micronaut-data-embedded-misleading-error-message

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant