Sidekick
Sidekick copied to clipboard
INC: Expose marp errors properly
In Sidekick/Logic/View Controllers/Tools/Slide Studio/SlideStudioViewController.c,
/// Function to start `marp` preview server
public func startPreview() {
// Save the code
self.saveMarkdownToFile()
// Start the marp child process
self.marpPreviewProcess = Process()
self.marpPreviewProcess.executableURL = Bundle
.main
.resourceURL?
.appendingPathComponent("marp")
let arguments = [
"--watch",
self.markdownPreviewFileUrl.posixPath,
"--output",
self.markdownPreviewUrl.posixPath
]
self.marpPreviewProcess.arguments = arguments
self.marpPreviewProcess.standardInput = FileHandle.nullDevice
// To debug with server's output, comment these 2 lines to inherit stdout.
self.marpPreviewProcess.standardOutput = FileHandle.nullDevice
self.marpPreviewProcess.standardError = FileHandle.nullDevice
// Run process
do {
try self.marpPreviewProcess.run()
} catch {
// Print error
print("Error generating diagram: \(error)")
// Return to first step
Task.detached { @MainActor in
Dialogs.showAlert(
title: String(localized: "Error"),
message: String(localized: "An error occurred while generating the slides.")
)
self.reset()
}
}
}
The error handling code is a bit too generic, it'd be useful to tell the user what actually occurred. Perhaps read them to a buffer? (Obviously I don't know swift but it seems like people say you should create a pipe and asynchronously read from it to a buffer, which seems a bit cumbersome but w/e)
Also the formatting of the code here is a bit inconsistent (=, = ).
errr, .swift, not .c