44 lines
1.7 KiB
Swift
44 lines
1.7 KiB
Swift
// LiveSessionError.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
// LyrebirdLiveCompile
|
|
//
|
|
// `LiveSession.compileAndRun(_:additive:)` throws this richer error so callers
|
|
// see diagnostics pre-mapped to user-snippet coordinates. Other `LiveCompileError`
|
|
// cases (toolchain missing, dlopen failure, etc.) pass through under
|
|
// `.compilerError`.
|
|
|
|
#if os(macOS)
|
|
|
|
public enum LiveSessionError: Error, CustomStringConvertible, Sendable {
|
|
/// Snippet failed to compile. `diagnostics` are already line-mapped via the
|
|
/// active `SnippetHarness` offset; `underlying` is the raw `swiftc` failure
|
|
/// the diagnostics were parsed from.
|
|
case snippetCompileFailed(diagnostics: [Diagnostic], underlying: LiveCompileError)
|
|
|
|
/// Any other `LiveCompileError` case — toolchain missing, dlopen failure,
|
|
/// missing entry symbol, IO failure.
|
|
case compilerError(LiveCompileError)
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .snippetCompileFailed(let diagnostics, let underlying):
|
|
if diagnostics.isEmpty {
|
|
return "snippet compile failed:\n\(underlying)"
|
|
}
|
|
let summary: String = diagnostics.map { diag -> String in
|
|
let location: String = diag.line.map { "\($0):\(diag.column)" } ?? "preamble:\(diag.rawLine):\(diag.column)"
|
|
return "\(location) \(diag.severity.rawValue): \(diag.message)"
|
|
}.joined(separator: "\n")
|
|
return "snippet compile failed:\n\(summary)"
|
|
case .compilerError(let underlying):
|
|
return "live compile error: \(underlying)"
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|