Skip to content

[BUG] ValidationResult.toString() has reversed check on if (!violation.toProto().hasField())) to write field #285

@ikeralmandoz

Description

@ikeralmandoz

Description

After upgrading to 0.6.0 and newer, we no longer get the field name in the log messages.
The issue is the change from

      if (!violation.toProto().getFieldPath().isEmpty()) {
        builder.append(violation.toProto().getFieldPath());
        builder.append(": ");
      }

to

      if (!violation.toProto().hasField()) {
        builder.append(FieldPathUtils.fieldPathString(violation.toProto().getField()));
        builder.append(": ");
      }

The fieldName should be written when hasField() is true, and not when it's false.

Steps to Reproduce

Execute any API call with a validation error. Message will look like this

value is empty, which is not a valid UUID [string.uuid_empty]

Expected Behavior

The error should show the fieldName as in version 0.5.0

fieldName: value is empty, which is not a valid UUID [string.uuid_empty]

Actual Behavior

Screenshots/Logs

Environment

  • Operating System: mXOA
  • Version: 14
  • Compiler/Toolchain: KOTLIN-1.9
  • Protobuf Compiler & Version: 4.30.2
  • Protovalidate Version: 0.7.2

Possible Solution

Change the condition to

      if (violation.toProto().hasField()) {
        builder.append(FieldPathUtils.fieldPathString(violation.toProto().getField()));
        builder.append(": ");
      }

Additional Context

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions