Skip to content

Don't pass file and line to runtime warnings #2059

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

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions Sources/ComposableArchitecture/Effect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ extension EffectPublisher where Failure == Never {
priority: TaskPriority? = nil,
operation: @escaping @Sendable () async throws -> Action,
catch handler: (@Sendable (Error) async -> Action)? = nil,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> Self {
Expand All @@ -197,9 +196,7 @@ extension EffectPublisher where Failure == Never {

All non-cancellation errors must be explicitly handled via the "catch" \
parameter on "EffectTask.task", or via a "do" block.
""",
file: file,
line: line
"""
)
#endif
return
Expand Down Expand Up @@ -255,7 +252,6 @@ extension EffectPublisher where Failure == Never {
priority: TaskPriority? = nil,
operation: @escaping @Sendable (Send<Action>) async throws -> Void,
catch handler: (@Sendable (Error, Send<Action>) async -> Void)? = nil,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> Self {
Expand All @@ -280,9 +276,7 @@ extension EffectPublisher where Failure == Never {

All non-cancellation errors must be explicitly handled via the "catch" parameter \
on "EffectTask.run", or via a "do" block.
""",
file: file,
line: line
"""
)
#endif
return
Expand Down
37 changes: 19 additions & 18 deletions Sources/ComposableArchitecture/Effects/TaskResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,28 @@ extension TaskResult: Equatable where Success: Equatable {
case let (.success(lhs), .success(rhs)):
return lhs == rhs
case let (.failure(lhs), .failure(rhs)):
return _isEqual(lhs, rhs) ?? {
#if DEBUG
let lhsType = type(of: lhs)
if TaskResultDebugging.emitRuntimeWarnings, lhsType == type(of: rhs) {
let lhsTypeName = typeName(lhsType)
runtimeWarn(
"""
"\(lhsTypeName)" is not equatable. …
return _isEqual(lhs, rhs)
?? {
#if DEBUG
let lhsType = type(of: lhs)
if TaskResultDebugging.emitRuntimeWarnings, lhsType == type(of: rhs) {
let lhsTypeName = typeName(lhsType)
runtimeWarn(
"""
"\(lhsTypeName)" is not equatable. …

To test two values of this type, it must conform to the "Equatable" protocol. For \
example:
To test two values of this type, it must conform to the "Equatable" protocol. For \
example:

extension \(lhsTypeName): Equatable {}
extension \(lhsTypeName): Equatable {}

See the documentation of "TaskResult" for more information.
"""
)
}
#endif
return false
}()
See the documentation of "TaskResult" for more information.
"""
)
}
#endif
return false
}()
default:
return false
}
Expand Down
4 changes: 1 addition & 3 deletions Sources/ComposableArchitecture/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,7 @@ extension AnyReducer {
To fix this make sure that actions for this reducer can only be sent to a view store \
when its state contains an element at this index. In SwiftUI applications, use \
"ForEachStore".
""",
file: file,
line: line
"""
)
return .none
}
Expand Down
10 changes: 2 additions & 8 deletions Sources/ComposableArchitecture/Internal/RuntimeWarnings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ import Foundation
@inline(__always)
func runtimeWarn(
_ message: @autoclosure () -> String,
category: String? = "ComposableArchitecture",
file: StaticString? = nil,
line: UInt? = nil
category: String? = "ComposableArchitecture"
) {
#if DEBUG
let message = message()
let category = category ?? "Runtime Warning"
if _XCTIsTesting {
if let file = file, let line = line {
XCTFail(message, file: file, line: line)
} else {
XCTFail(message)
}
XCTFail(message)
} else {
#if canImport(os)
os_log(
Expand Down
16 changes: 4 additions & 12 deletions Sources/ComposableArchitecture/Reducer/AnyReducer/AnyReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,7 @@ public struct AnyReducer<State, Action, Environment> {
• This action was sent to the store while state was another case. Make sure that \
actions for this reducer can only be sent to a view store when state is non-"nil". \
In SwiftUI applications, use "SwitchStore".
""",
file: file,
line: line
"""
)
return .none
}
Expand Down Expand Up @@ -931,9 +929,7 @@ public struct AnyReducer<State, Action, Environment> {
• This action was sent to the store while state was "nil". Make sure that actions for \
this reducer can only be sent to a view store when state is non-"nil". In SwiftUI \
applications, use "IfLetStore".
""",
file: file,
line: line
"""
)
return .none
}
Expand Down Expand Up @@ -1052,9 +1048,7 @@ public struct AnyReducer<State, Action, Environment> {
To fix this make sure that actions for this reducer can only be sent to a view store \
when its state contains an element at this id. In SwiftUI applications, use \
"ForEachStore".
""",
file: file,
line: line
"""
)
return .none
}
Expand Down Expand Up @@ -1120,9 +1114,7 @@ public struct AnyReducer<State, Action, Environment> {
• This action was sent to the store while its state contained no element at this \
key. To fix this make sure that actions for this reducer can only be sent to a view \
store when its state contains an element at this key.
""",
file: file,
line: line
"""
)
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ extension ReducerProtocol {
_ toElementsState: WritableKeyPath<State, IdentifiedArray<ID, ElementState>>,
action toElementAction: CasePath<Action, (ID, ElementAction)>,
@ReducerBuilder<ElementState, ElementAction> element: () -> Element,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> _ForEachReducer<Self, ID, Element>
Expand All @@ -65,7 +64,6 @@ extension ReducerProtocol {
toElementsState: toElementsState,
toElementAction: toElementAction,
element: element(),
file: file,
fileID: fileID,
line: line
)
Expand All @@ -87,9 +85,6 @@ public struct _ForEachReducer<
@usableFromInline
let element: Element

@usableFromInline
let file: StaticString

@usableFromInline
let fileID: StaticString

Expand All @@ -102,15 +97,13 @@ public struct _ForEachReducer<
toElementsState: WritableKeyPath<Parent.State, IdentifiedArray<ID, Element.State>>,
toElementAction: CasePath<Parent.Action, (ID, Element.Action)>,
element: Element,
file: StaticString,
fileID: StaticString,
line: UInt
) {
self.parent = parent
self.toElementsState = toElementsState
self.toElementAction = toElementAction
self.element = element
self.file = file
self.fileID = fileID
self.line = line
}
Expand Down Expand Up @@ -149,9 +142,7 @@ public struct _ForEachReducer<
• This action was sent to the store while its state contained no element at this ID. To \
fix this make sure that actions for this reducer can only be sent from a view store when \
its state contains an element at this id. In SwiftUI applications, use "ForEachStore".
""",
file: self.file,
line: self.line
"""
)
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ extension ReducerProtocol {
_ toCaseState: CasePath<State, CaseState>,
action toCaseAction: CasePath<Action, CaseAction>,
@ReducerBuilder<CaseState, CaseAction> then case: () -> Case,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> _IfCaseLetReducer<Self, Case>
Expand All @@ -61,7 +60,6 @@ extension ReducerProtocol {
child: `case`(),
toChildState: toCaseState,
toChildAction: toCaseAction,
file: file,
fileID: fileID,
line: line
)
Expand All @@ -81,9 +79,6 @@ public struct _IfCaseLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>
@usableFromInline
let toChildAction: CasePath<Parent.Action, Child.Action>

@usableFromInline
let file: StaticString

@usableFromInline
let fileID: StaticString

Expand All @@ -96,15 +91,13 @@ public struct _IfCaseLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>
child: Child,
toChildState: CasePath<Parent.State, Child.State>,
toChildAction: CasePath<Parent.Action, Child.Action>,
file: StaticString,
fileID: StaticString,
line: UInt
) {
self.parent = parent
self.child = child
self.toChildState = toChildState
self.toChildAction = toChildAction
self.file = file
self.fileID = fileID
self.line = line
}
Expand Down Expand Up @@ -148,9 +141,7 @@ public struct _IfCaseLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>
• This action was sent to the store while state was another case. Make sure that actions \
for this reducer can only be sent from a view store when state is set to the appropriate \
case. In SwiftUI applications, use "SwitchStore".
""",
file: self.file,
line: self.line
"""
)
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extension ReducerProtocol {
_ toWrappedState: WritableKeyPath<State, WrappedState?>,
action toWrappedAction: CasePath<Action, WrappedAction>,
@ReducerBuilder<WrappedState, WrappedAction> then wrapped: () -> Wrapped,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) -> _IfLetReducer<Self, Wrapped>
Expand All @@ -58,7 +57,6 @@ extension ReducerProtocol {
child: wrapped(),
toChildState: toWrappedState,
toChildAction: toWrappedAction,
file: file,
fileID: fileID,
line: line
)
Expand All @@ -78,9 +76,6 @@ public struct _IfLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>: Re
@usableFromInline
let toChildAction: CasePath<Parent.Action, Child.Action>

@usableFromInline
let file: StaticString

@usableFromInline
let fileID: StaticString

Expand All @@ -93,15 +88,13 @@ public struct _IfLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>: Re
child: Child,
toChildState: WritableKeyPath<Parent.State, Child.State?>,
toChildAction: CasePath<Parent.Action, Child.Action>,
file: StaticString,
fileID: StaticString,
line: UInt
) {
self.parent = parent
self.child = child
self.toChildState = toChildState
self.toChildAction = toChildAction
self.file = file
self.fileID = fileID
self.line = line
}
Expand Down Expand Up @@ -142,9 +135,7 @@ public struct _IfLetReducer<Parent: ReducerProtocol, Child: ReducerProtocol>: Re
• This action was sent to the store while state was "nil". Make sure that actions for this \
reducer can only be sent from a view store when state is non-"nil". In SwiftUI \
applications, use "IfLetStore".
""",
file: self.file,
line: self.line
"""
)
return .none
}
Expand Down
10 changes: 3 additions & 7 deletions Sources/ComposableArchitecture/Reducer/Reducers/Scope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
enum StatePath {
case casePath(
CasePath<ParentState, Child.State>,
file: StaticString,
fileID: StaticString,
line: UInt
)
Expand Down Expand Up @@ -225,12 +224,11 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
state toChildState: CasePath<ParentState, ChildState>,
action toChildAction: CasePath<ParentAction, ChildAction>,
@ReducerBuilder<ChildState, ChildAction> child: () -> Child,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
) where ChildState == Child.State, ChildAction == Child.Action {
self.init(
toChildState: .casePath(toChildState, file: file, fileID: fileID, line: line),
toChildState: .casePath(toChildState, fileID: fileID, line: line),
toChildAction: toChildAction,
child: child()
)
Expand All @@ -243,7 +241,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
guard let childAction = self.toChildAction.extract(from: action)
else { return .none }
switch self.toChildState {
case let .casePath(toChildState, file, fileID, line):
case let .casePath(toChildState, fileID, line):
guard var childState = toChildState.extract(from: state) else {
runtimeWarn(
"""
Expand Down Expand Up @@ -272,9 +270,7 @@ public struct Scope<ParentState, ParentAction, Child: ReducerProtocol>: ReducerP
• This action was sent to the store while state was another case. Make sure that actions \
for this reducer can only be sent from a view store when state is set to the appropriate \
case. In SwiftUI applications, use "SwitchStore".
""",
file: file,
line: line
"""
)
return .none
}
Expand Down
Loading