Skip to content

[do-not-merge] Generate a file with TypeMarkers for each errors namespace#2846

Open
mpritham wants to merge 4 commits intodevelopfrom
pm/reduce-anon-classes
Open

[do-not-merge] Generate a file with TypeMarkers for each errors namespace#2846
mpritham wants to merge 4 commits intodevelopfrom
pm/reduce-anon-classes

Conversation

@mpritham
Copy link
Copy Markdown
Contributor

Before this PR

Each Dialogue service interface constructs two TypeMarkers per Conjure error:

new TypeMarker<
exceptionthrowingdialogueinterfaces.com.palantir.another.ConjureErrors
.DifferentPackageErrorSerializableError>() {},
new TypeMarker<
exceptionthrowingdialogueinterfaces.com.palantir.another.ConjureErrors
.DifferentPackageErrorException>() {})

The construction of these TypeMarkers are duplicated in every service in defined in the Conjure definition with the declared errors. For some projects with many errors and services, this leads to a sharp increase in the number of anonymous classes generated which creates load on build tooling: e.g. JARs need to be compressed and lots more classes need to be loaded.

After this PR

A new {Namespace}ErrorsTypeMarkers class is generated per error namespace in the Dialogue output, holding
shared public static final TypeMarker constants:

  public final class ConjureErrorsTypeMarkers {
      public static final TypeMarker<ConjureErrors.ConflictingCauseSafeArgSerializableError>
              CONFLICTING_CAUSE_SAFE_ARG_SERIALIZABLE_ERROR = new TypeMarker<...>() {};
      // ...
      private ConjureErrorsTypeMarkers() {}
  }

Service interfaces now reference these constants instead of creating anonymous classes:

  .exception(
          ConjureErrors.CONFLICTING_CAUSE_SAFE_ARG.name(),
          ConjureErrorsTypeMarkers.CONFLICTING_CAUSE_SAFE_ARG_SERIALIZABLE_ERROR,
          ConjureErrorsTypeMarkers.CONFLICTING_CAUSE_SAFE_ARG_EXCEPTION)

The TypeMarkers class is generated into the -dialogue project (not the -objects output) so it doesn't require adding dialogue-target as a dependency to the objects project.

==COMMIT_MSG==
Generate a file with TypeMarkers for each errors namespace
==COMMIT_MSG==

Possible downsides?

I would've preferred to generate these TypeMarker anonymous classes in each of the generated <Error>SerializableError and <Error>Exception classes, but the TypeMarker is defined in dialogue-target and I did not want to force all consumers to -objects JARs to require a new API dep on dialogue-target.

I don't think there is anything specific to dialogue about TypeMarker: in the future, we can consider moving this class out to another project.

@changelog-app
Copy link
Copy Markdown

changelog-app bot commented Mar 23, 2026

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Generate a file with TypeMarkers for each errors namespace

Check the box to generate changelog(s)

  • Generate changelog entry

bjlaub
bjlaub previously approved these changes Mar 23, 2026
Copy link
Copy Markdown
Contributor

@bjlaub bjlaub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving for RC

@policy-bot policy-bot bot dismissed bjlaub’s stale review March 23, 2026 19:59

Invalidated by push of b8e7e48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants