palantir / palantir/conjure-java-runtime-api

Better error message for type mismatch in test-utils' argument assertions

Open
#876 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
6
Forks
33
Avg merge
15h 50m
Merged PRs (30d)
12

Description

What happened?

I recently got this error message:

java.lang.AssertionError: Expected unsafe args to be {extra=[extra], missing=[missing_secret, missing_secret2]}, but found {extra=[extra], missing=[missing_secret, missing_secret_2]}

which is confusing because it looks like expected and actual are the same. Actually, their types are different -- one is a String "[extra]" and one is a Set ImmutableSet.of("extra").

In the case where two objects are different, but their toStrings() are equal, we should additionally show in the error message the types of the two objects.

This would happen here: https://github.com/palantir/conjure-java-runtime-api/blob/41e7566f4e10dcca131019a3d65d6a3b4e0beb28/test-utils/src/main/java/com/palantir/conjure/java/api/testing/ServiceExceptionAssert.java#L68

Minimal repo:

        assertThatServiceExceptionThrownBy(() -> {
                    throw new ServiceException(ErrorType.INTERNAL, UnsafeArg.of("list", ImmutableList.of("a")));
                })
                .hasArgs(UnsafeArg.of("list", "[a]"));

currently gives message:

java.lang.AssertionError: Expected unsafe args to be {list=[a]}, but found {list=[a]}

What did you want to happen?

Should return a message like:

java.lang.AssertionError: Expected unsafe args to be {list=[a]} with value type String, but found {list=[a]} with value type ImmutableList<String>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at test-utils/src/main/java/com/palantir/conjure/java/api/testing/ServiceExceptionAssert.java around line 68, where the unsafe-argument assertion builds its error message. Use the minimal ServiceException example to reproduce the equal-toString mismatch, then verify that differing value types appear in the message and that matching values remain readable.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.