Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit d07af88

Browse files
authored
fix crash in Navigation.debugDescription, wrap os_log (#1120)
Task/Issue URL: https://app.asana.com/0/1177771139624306/1204359032555835/f BSK PR: duckduckgo/BrowserServicesKit#312 iOS PR: duckduckgo/iOS#1638 **Description**: - fixed the navigation flow when fragment Navigation could end-up without a NavigationAction assigned - introduced os_log wrapper in BSK to accept message arguments as autoclosures i.e. computed only if valid log and log level are passed **Steps to test this PR**: 1. Validate that every Navigation appearing in willStart and didStart NavigationResponder calls has a NavigationAction assigned (DistributedNavigationDelegate.swift:279) - only actual for macOS now 2. Validate `os_log` calls across the codebase don‘t need changing (only need to replace `replace import` os with `import Common`), arguments passed as %s and %d parameters are printed correctly, to the right log and with correct log level. Validate interpolated string passed to `os_log` works (`os_log("interpolated \(string)")`) 3. Validate `import os.log` is discouraged by swiftlint in favour of `import Common` 4. Validate Debug->Logging menu is working as intended including BSK logging categories <!-- Tagging instructions If this PR isn't ready to be merged for whatever reason it should be marked with the `DO NOT MERGE` label (particularly if it's a draft) If it's pending Product Review/PFR, please add the `Pending Product Review` label. If at any point it isn't actively being worked on/ready for review/otherwise moving forward (besides the above PR/PFR exception) strongly consider closing it (or not opening it in the first place). If you decide not to close it, make sure it's labelled to make it clear the PRs state and comment with more information. --> --- ###### Internal references: [Pull Request Review Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f) [Software Engineering Expectations](https://app.asana.com/0/59792373528535/199064865822552) [Technical Design Template](https://app.asana.com/0/59792373528535/184709971311943) **When ready for review, remember to post the PR in MM**
1 parent 26d2c89 commit d07af88

File tree

95 files changed

+95
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+95
-210
lines changed

.swiftlint.yml

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ custom_rules:
2222
- keyword
2323
message: "Classes should be `final` by default, use explicit `internal` or `public` for non-final classes."
2424
severity: error
25+
enforce_os_log_wrapper:
26+
included: ".*\\.swift"
27+
name: "Use `import Common` for os_log instead of `import os.log`"
28+
regex: "^(import (?:os\\.log|os|OSLog))$"
29+
capture_group: 0
30+
message: "os_log wrapper ensures log args are @autoclosures (computed when needed) and to be able to use String Interpolation."
31+
severity: error
2532

2633
# Rule Config
2734
identifier_name:

DuckDuckGo.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8603,7 +8603,7 @@
86038603
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
86048604
requirement = {
86058605
kind = exactVersion;
8606-
version = 56.0.0;
8606+
version = 56.1.0;
86078607
};
86088608
};
86098609
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {

DuckDuckGo.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
77
"state" : {
8-
"revision" : "f2e2f9bf09de04633f7a0648d994af08a999c335",
9-
"version" : "56.0.0"
8+
"revision" : "dc2d52b28719355baafb6a58ac6b76f3ae734553",
9+
"version" : "56.1.0"
1010
}
1111
},
1212
{

DuckDuckGo/AppDelegate/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import Cocoa
2020
import Combine
21-
import os.log
21+
import Common
2222
import BrowserServicesKit
2323
import Persistence
2424
import Configuration

DuckDuckGo/AppDelegate/URLEventHandler.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os.log
2121

2222
@MainActor
2323
final class URLEventHandler {

DuckDuckGo/Autoconsent/AutoconsentUserScript.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//
1818

1919
import WebKit
20-
import os
2120
import BrowserServicesKit
21+
import Common
2222
import UserScript
2323
import PrivacyDashboard
2424

DuckDuckGo/Bookmarks/Legacy/LegacyBookmarkStore.swift

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import Foundation
2020
import CoreData
2121
import Cocoa
22-
import os.log
2322

2423
fileprivate extension UUID {
2524

DuckDuckGo/Bookmarks/Legacy/LegacyBookmarksStoreMigration.swift

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import Foundation
2020
import CoreData
2121
import Bookmarks
2222
import Persistence
23-
import os.log
2423

2524
public class LegacyBookmarksStoreMigration {
2625

DuckDuckGo/Bookmarks/Model/BookmarkList.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import Foundation
2020
import BrowserServicesKit
21-
import os.log
21+
import Common
2222

2323
struct BookmarkList {
2424

DuckDuckGo/Bookmarks/Model/BookmarkManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//
1818

1919
import Cocoa
20-
import os.log
2120
import Combine
21+
import Common
2222

2323
protocol BookmarkManager: AnyObject {
2424

DuckDuckGo/Bookmarks/Model/BookmarkOutlineViewDataSource.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//
1818

1919
import AppKit
20+
import Common
2021
import Foundation
21-
import os.log
2222

2323
final class BookmarkOutlineViewDataSource: NSObject, NSOutlineViewDataSource, NSOutlineViewDelegate {
2424

DuckDuckGo/Bookmarks/Services/LocalBookmarkStore.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
2021
import CoreData
2122
import Bookmarks
2223
import Cocoa
23-
import os.log
2424

2525
// swiftlint:disable:next type_body_length
2626
final class LocalBookmarkStore: BookmarkStore {

DuckDuckGo/Bookmarks/View/BookmarkManagementDetailViewController.swift

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import AppKit
2020
import Combine
21-
import os
2221

2322
protocol BookmarkManagementDetailViewControllerDelegate: AnyObject {
2423

DuckDuckGo/BookmarksBar/View/BookmarksBarViewController.swift

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import Foundation
2020
import AppKit
2121
import Combine
22-
import os.log
2322

2423
final class BookmarksBarViewController: NSViewController {
2524

DuckDuckGo/Common/Extensions/FileManagerExtension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os
2121

2222
extension FileManager {
2323

DuckDuckGo/Common/Extensions/NSTextFieldExtension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//
1818

1919
import Cocoa
20-
import os.log
20+
import Common
2121

2222
extension NSTextField {
2323

DuckDuckGo/Common/Extensions/NSViewExtension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import Cocoa
2020
import Combine
21-
import os.log
21+
import Common
2222

2323
extension NSView {
2424

DuckDuckGo/Common/Extensions/StringExtension.swift

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//
1818

1919
import Foundation
20-
import os.log
2120
import BrowserServicesKit
2221

2322
extension String {

DuckDuckGo/Common/Extensions/URLExtension.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os.log
2121
import BrowserServicesKit
2222

2323
extension URL.NavigationalScheme {

DuckDuckGo/Common/Logging/Logging.swift

+19-28
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os
21+
import os.log // swiftlint:disable:this enforce_os_log_wrapper
2122

2223
extension OSLog {
2324

24-
enum Categories: String, CaseIterable {
25+
enum AppCategories: String, CaseIterable {
2526
case atb = "ATB"
2627
case config = "Configuration Downloading"
2728
case fire = "Fire"
@@ -41,11 +42,15 @@ extension OSLog {
4142
case navigation = "Navigation"
4243
case duckPlayer = "Duck Player"
4344
}
45+
enum AllCategories {
46+
static var allCases: [String] {
47+
Categories.allCases.map(\.rawValue) + AppCategories.allCases.map(\.rawValue)
48+
}
49+
}
4450

4551
@OSLogWrapper(.atb) static var atb
4652
@OSLogWrapper(.config) static var config
4753
@OSLogWrapper(.fire) static var fire
48-
@OSLogWrapper(.passwordManager) static var passwordManager
4954
@OSLogWrapper(.history) static var history
5055
@OSLogWrapper(.dataImportExport) static var dataImportExport
5156
@OSLogWrapper(.pixel) static var pixel
@@ -61,12 +66,6 @@ extension OSLog {
6166
@OSLogWrapper(.navigation) static var navigation
6267
@OSLogWrapper(.duckPlayer) static var duckPlayer
6368

64-
#if DEBUG
65-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
66-
// To activate Logging Categories for DEBUG add categories here:
67-
static var debugCategories: Set<Categories> = [ /* .navigation... */ ]
68-
#endif
69-
7069
// Debug->Logging categories will only be enabled for one day
7170
@UserDefaultsWrapper(key: .loggingEnabledDate, defaultValue: .distantPast)
7271
private static var loggingEnabledDate: Date
@@ -80,13 +79,14 @@ extension OSLog {
8079
loggingEnabledDate = Date()
8180
}
8281
}
83-
static var loggingCategories: Set<Categories> {
82+
static var loggingCategories: Set<String> {
8483
get {
8584
guard isLoggingEnabledToday else { return [] }
86-
return Set(loggingCategoriesSetting.compactMap(Categories.init(rawValue:)))
85+
return Set(loggingCategoriesSetting)
8786
}
8887
set {
89-
loggingCategoriesSetting = Array(newValue.map(\.rawValue))
88+
loggingCategoriesSetting = Array(newValue)
89+
enabledLoggingCategories = loggingCategories
9090
}
9191
}
9292

@@ -108,24 +108,15 @@ extension ProcessInfo {
108108
}
109109
}
110110

111-
@propertyWrapper
112-
struct OSLogWrapper {
111+
extension OSLog.OSLogWrapper {
113112

114-
let category: OSLog.Categories
115-
116-
var wrappedValue: OSLog {
117-
var isEnabled = OSLog.loggingCategories.contains(category)
118-
#if CI
119-
isEnabled = true
120-
#elseif DEBUG
121-
isEnabled = isEnabled || OSLog.debugCategories.contains(category)
122-
#endif
123-
124-
return isEnabled ? OSLog(subsystem: OSLog.subsystem, category: category.rawValue) : .disabled
125-
}
113+
private static let enableLoggingCategoriesOnce: Void = {
114+
OSLog.enabledLoggingCategories = OSLog.loggingCategories
115+
}()
126116

127-
init(_ category: OSLog.Categories) {
128-
self.category = category
117+
init(_ category: OSLog.AppCategories) {
118+
_=Self.enableLoggingCategoriesOnce
119+
self.init(rawValue: category.rawValue)
129120
}
130121

131122
}

DuckDuckGo/Configuration/ConfigurationManager.swift

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import Foundation
2020
import Combine
21-
import os
2221
import BrowserServicesKit
2322
import Configuration
2423
import Common

DuckDuckGo/Configuration/ConfigurationStore.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os
2121
import Configuration
2222

2323
final class ConfigurationStore: ConfigurationStoring {

DuckDuckGo/ContentBlocker/ContentBlocking.swift

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import Foundation
2020
import WebKit
2121
import Combine
22-
import os.log
2322
import BrowserServicesKit
2423
import Common
2524

DuckDuckGo/DataImport/Bookmarks/Safari/SafariBookmarksReader.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os.log
2121

2222
final class SafariBookmarksReader {
2323

DuckDuckGo/DataImport/View/DataImportViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import AppKit
2020
import BrowserServicesKit
2121
import Combine
22-
import os.log
22+
import Common
2323

2424
final class DataImportViewController: NSViewController {
2525

DuckDuckGo/DeviceAuthentication/DeviceAuthenticator.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import Foundation
2020
import LocalAuthentication
21-
import os.log
21+
import Common
2222

2323
extension NSNotification.Name {
2424

DuckDuckGo/DeviceAuthentication/QuartzIdleStateProvider.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
//
1818

1919
import Foundation
20+
import Common
2021
import CoreGraphics
21-
import os.log
2222

2323
final class QuartzIdleStateProvider: DeviceIdleStateProvider {
2424

DuckDuckGo/Favicons/Model/FaviconImageCache.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import Foundation
2020
import Combine
21-
import os.log
21+
import Common
2222
import BrowserServicesKit
2323

2424
final class FaviconImageCache {

DuckDuckGo/Favicons/Model/FaviconReferenceCache.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import Foundation
2020
import Combine
21-
import os.log
21+
import Common
2222
import BrowserServicesKit
2323

2424
final class FaviconReferenceCache {

DuckDuckGo/Favicons/Services/FaviconStore.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import Cocoa
2020
import CoreData
2121
import Combine
22-
import os.log
22+
import Common
2323

2424
protocol FaviconStoring {
2525

DuckDuckGo/Feedback/Model/FeedbackSender.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
// limitations under the License.
1717
//
1818

19+
import Common
1920
import Foundation
20-
import os.log
2121
import Networking
2222

2323
final class FeedbackSender {

DuckDuckGo/FileDownload/Model/FileDownloadManager.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
import AppKit
2020
import Combine
21+
import Common
2122
import Navigation
22-
import os
2323

2424
protocol FileDownloadManagerProtocol: AnyObject {
2525
var downloads: Set<WebKitDownloadTask> { get }

0 commit comments

Comments
 (0)