Hello!
I have a SwiftUI View with associated previews that are failing to build with the following error message:
CompileDylibError: Failed to build CreateSwiftCompilationDatabase.swift
Compiling failed: call can throw, but it is not marked with 'try' and the error is not handled
/Users/feifan/Library/Developer/Xcode/DerivedData/Visualize-btsxhyyrvfibcbedigiqvajgduqa/Build/Intermediates.noindex/Previews/Visualize/Intermediates.noindex/Visualize.build/Debug/Visualize.build/Objects-normal/x86_64/CreateSwiftCompilationDatabase.1.preview-thunk.swift:920:12: error: call can throw, but it is not marked with 'try' and the error is not handled
return CreateSwiftCompilationDatabaseFeature.compilationDatabaseOutputString(forFileItems: fileItems, selectedFiles: selectedFiles)
… etc (there are multiple other line numbers listed, all with the same error)
Opening the named CreateSwiftCompilationDatabase.1.preview-thunk.swift
file, which I didn't write, I do see the following on lines 919–921:
private func compilationDatabaseOutputString(forFileItems fileItems: [FileItem], selectedFiles: Set<FileItem.ID>) -> String {
return CreateSwiftCompilationDatabaseFeature.compilationDatabaseOutputString(forFileItems: fileItems, selectedFiles: selectedFiles)
}
and indeed, CreateSwiftCompilationDatabaseFeature.compilationDatabaseOutputString
, which is code I've actually written, is defined as a throws
function.
static func compilationDatabaseOutputString(forFileItems fileItems: [FileItem], selectedFiles: Set<FileItem.ID>) throws -> String {
…
}
This issue repros across running a clean, quitting Xcode, and even deleting the entire DerivedData
directory for my project. It looks like the preview-thunk.swift
file is being generated incorrectly (it should include a try
, but it isn't). I'm not sure where that preview-thunk.swift
file is coming from though.
This only affects previews for this view; my app itself builds and runs without a problem.
Am I doing something wrong/can I fix how the preview-thunk.swift
file is generated, or is this a Swift bug?