-
Notifications
You must be signed in to change notification settings - Fork 102
Require explicit backtrace and source location when creating and recording issues #688
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Require explicit backtrace and source location when creating and recording issues #688
Conversation
This is internal code, so it doesn't make a huge difference, but… the intent behind not having a default value is to force us callers to always spell it out, lest we accidentally forget to forward comments from our own callers. Is this fixing a known issue or just housekeeping? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change would introduce regressions in our backtrace quality and could cause us to record issues with no source context at all.
…. Instead, require callers pass it explicitly
@swift-ci please test |
This refactors some of the logic for constructing
SourceContext
andIssue
instances to require explicit arguments in more places.Motivation:
We can provide clearer and more relevant details about recorded issues by ensuring that their backtrace and/or source location are accurate. In general, whenever collecting a backtrace, it's better to elide unhelpful frames from the testing library itself so that frames from user code are as close to the top of the call stack as possible. Similarly, whenever an explicit source location is known, it's best to propagate that in any recorded issues which originate at that location.
Currently, the
SourceContext
type has default parameter values for both itsbacktrace
andsourceLocation
properties. Having default values for these parameters means that callers elsewhere in the codebase may accidentally not specify a value, thereby not propagating useful information. Or, in the case of backtraces, they may rely on the default value which results in additional, irrelevant frames in the call stack (representing thunks inserted by the compiler for the default value). The initializer forIssue
also includes a default value for one of its parameters.Modifications:
SourceContext.init(...)
to remove the default values for both of its parameters:backtrace:
andsourceLocation:
.Issue.init(...)
to no longer have default values for any of its parameters.Issue.record(...)
functions, and change callers to rely on the instancerecord(configuration:)
method. This consolidates the usage pattern across theTesting
module for creating anIssue
and then recording it.SkipInfo.init(...)
to remove the default value for itssourceContext:
parameter.init(for:sourceLocation:)
which accepts anError
and correctly creates aSourceContext
for it.TestingAdditions.swift
which preserve default parameter values, to avoid unnecessary boilerplate in test-only code where it's safe to rely on such default values.Checklist: