Skip to content

Instantly share code, notes, and snippets.

@ronshapiro
Last active May 11, 2018 15:30
Show Gist options
  • Save ronshapiro/0920391011e6f253bc598cc4c0e69a34 to your computer and use it in GitHub Desktop.
Save ronshapiro/0920391011e6f253bc598cc4c0e69a34 to your computer and use it in GitHub Desktop.

Most Dagger errors are in the format:

src/main/java/dagger/playground/Playground.java:20: [Dagger/DuplicateBindings] dagger.playground.E is bound multiple times:
  A a();
    ^
      @Provides dagger.playground.E dagger.playground.Mod.first()
      @Provides dagger.playground.E dagger.playground.Mod.second()
  
      dagger.playground.E is injected at
          dagger.playground.D.<init>(e)
      dagger.playground.D is injected at
          dagger.playground.C.<init>(d)
      dagger.playground.C is injected at
          dagger.playground.B.<init>(c)
      dagger.playground.B is injected at
          dagger.playground.A.<init>(b)
      dagger.playground.A is provided at
          dagger.playground.Component.a()
package dagger.playground;

class A {
  @Inject A(B b) {}
}
class B {
  @Inject B(C c) {}
}
class C {
  @Inject C(D d) {}
}
class D {
  @Inject D(E e) {}
}

class E {}

@dagger.Module
interface Mod {
  @Provides
  static E first() {
    return new E();
  }
  
  @Provides
  static E second() {
    return new E();
  }
}

@dagger.Component(modules = Mod.class)
interface Component {
  A a();
}

The format is hard to read, for a few reasons:

  • The file path, especially in larger projects, is quite long. It takes up a good chunk of the first line of the diagnostic. This is a general diagnostic problem not particular to Dagger
  • Our errors are multiple lines, but weren't designed to match the behavior of javac's diagnostic formatting. This is probably because we do most of our unit testing with github.com/google-compile-testing, which returns the Diagnostic unformatted. Here's the openjdk revision that began splitting up diagnostics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment