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

Swallow type errors if possible #183

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

navijation
Copy link

@navijation navijation commented Jun 21, 2021

Fixes

Summary

In the event that a source package contains type errors, refrain from fast-failing immediately upon package load.
Defer the failure to the point at which the target interface's methods are analyzed and found to contain invalid
types.

Motivation

packages.Load tends to be a performance bottleneck for larger projects (hence #181). However, it seems that removing
it require a large architectural change to counterfeiter internals, namely analysis of file ASTs to create a more limited,
lazy version of packages.Load.

Certain build systems, namely Bazel, can limit the cost of package loading by sandboxing a GOPATH much smaller than
the entire dependency tree of a package and running Counterfeiter in the sandbox. However, Counterfeiter crashes if any
import in the target package is unresolved, which limits the extent of this optimization.

Downsides

  • Creating tests with non-compiling packages seems rather complex (see changes to script/ci.sh) and might need
    to be thought out more carefully
  • The package loader doesn't seem to preserve unresolved symbols from the AST, so error messages list an
    erroneous signature as MethodName(param1 Type1, invalid type, invalid type)(invalid type, error). This might be
    the best option short of custom AST analysis.

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

Successfully merging this pull request may close these issues.

1 participant