Skip to content

Commit fd29262

Browse files
authored
Errors thrown while saving attachments should be recorded with warning severity. (#1530)
If an error is thrown while saving an attachment, Swift Testing fails the test whence the attachment was recorded. This is overly strict as the test itself may have run successfully. Developers who need those attachments will notice they're missing and be able to review the test log to see what went wrong. Resolves rdar://169742988. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent b6c646f commit fd29262

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

Sources/Testing/Attachments/Attachment.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extension Attachment where AttachableValue: ~Copyable {
307307
Attachment<Array>.record(bufferCopy, sourceLocation: sourceLocation)
308308
} catch {
309309
let sourceContext = SourceContext(backtrace: .current(), sourceLocation: sourceLocation)
310-
Issue(kind: .valueAttachmentFailed(error), comments: [], sourceContext: sourceContext).record()
310+
Issue(kind: .valueAttachmentFailed(error), severity: .warning, comments: [], sourceContext: sourceContext).record()
311311
}
312312
}
313313

@@ -536,7 +536,7 @@ extension Configuration {
536536
} catch {
537537
// Record the error as an issue and suppress the event.
538538
let sourceContext = SourceContext(backtrace: .current(), sourceLocation: attachment.sourceLocation)
539-
Issue(kind: .valueAttachmentFailed(error), comments: [], sourceContext: sourceContext).record(configuration: self)
539+
Issue(kind: .valueAttachmentFailed(error), severity: .warning, comments: [], sourceContext: sourceContext).record(configuration: self)
540540
return false
541541
}
542542
}

Tests/TestingTests/AttachmentTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ struct AttachmentTests {
254254
valueAttached()
255255
} else if case let .issueRecorded(issue) = event.kind,
256256
case let .valueAttachmentFailed(error) = issue.kind,
257+
issue.severity == .warning,
257258
error is MyError {
258259
#expect(issue.sourceLocation?.fileID == #fileID)
259260
issueRecorded()

0 commit comments

Comments
 (0)