Improved bug report error handling (#1018)

* Improve rageshake error handling.

* Add a max file size and exclude older files one the limit is hit.

* Zip log files as smaller chunks.
This commit is contained in:
Doug
2023-06-06 09:24:01 +01:00
committed by GitHub
parent 4e926c3334
commit ea4aa943e0
11 changed files with 279 additions and 100 deletions
+33 -7
View File
@@ -24,7 +24,7 @@ class BugReportServiceTests: XCTestCase {
override func setUpWithError() throws {
bugReportService = BugReportServiceMock()
bugReportService.underlyingCrashedLastRun = false
bugReportService.submitBugReportProgressListenerReturnValue = SubmitBugReportResponse(reportUrl: "https://www.example.com/123")
bugReportService.submitBugReportProgressListenerReturnValue = .success(SubmitBugReportResponse(reportUrl: "https://www.example.com/123"))
}
func testInitialStateWithMockService() {
@@ -39,8 +39,8 @@ class BugReportServiceTests: XCTestCase {
includeCrashLog: true,
githubLabels: [],
files: [])
let result = try await bugReportService.submitBugReport(bugReport, progressListener: nil)
XCTAssertFalse(result.reportUrl.isEmpty)
let response = try await bugReportService.submitBugReport(bugReport, progressListener: nil).get()
XCTAssertFalse(response.reportUrl.isEmpty)
}
func testInitialStateWithRealService() throws {
@@ -64,17 +64,43 @@ class BugReportServiceTests: XCTestCase {
includeCrashLog: true,
githubLabels: [],
files: [])
let result = try await service.submitBugReport(bugReport, progressListener: nil)
let response = try await service.submitBugReport(bugReport, progressListener: nil).get()
XCTAssertEqual(result.reportUrl, "https://example.com/123")
XCTAssertEqual(response.reportUrl, "https://example.com/123")
}
func testLogsMaxSize() {
// Given a new set of logs
var logs = BugReportService.Logs(maxFileSize: 1000)
XCTAssertEqual(logs.zippedSize, 0)
XCTAssertEqual(logs.originalSize, 0)
XCTAssertTrue(logs.files.isEmpty)
// When adding new files within the size limit
logs.appendFile(at: .homeDirectory, zippedSize: 250, originalSize: 1000)
logs.appendFile(at: .picturesDirectory, zippedSize: 500, originalSize: 2000)
// Then the logs should be included
XCTAssertEqual(logs.zippedSize, 750)
XCTAssertEqual(logs.originalSize, 3000)
XCTAssertEqual(logs.files, [.homeDirectory, .picturesDirectory])
// When adding a new file larger that will exceed the size limit
logs.appendFile(at: .homeDirectory, zippedSize: 500, originalSize: 2000)
// Then the files shouldn't be included.
XCTAssertEqual(logs.zippedSize, 750)
XCTAssertEqual(logs.originalSize, 3000)
XCTAssertEqual(logs.files, [.homeDirectory, .picturesDirectory])
}
}
private class MockURLProtocol: URLProtocol {
override func startLoading() {
let response = "{\"report_url\":\"https://example.com/123\"}"
if let data = response.data(using: .utf8) {
let urlResponse = URLResponse()
if let data = response.data(using: .utf8),
let url = request.url,
let urlResponse = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil) {
client?.urlProtocol(self, didReceive: urlResponse, cacheStoragePolicy: .allowedInMemoryOnly)
client?.urlProtocol(self, didLoad: data)
client?.urlProtocolDidFinishLoading(self)