// 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) /// The interpreted graph-DSL failed to lex/parse/build or its graphs were /// rejected by the engine. `diagnostics` are already mapped to user-source /// coordinates (a parse error resolves to a line/column; a build error has /// `line: nil`). No swiftc is involved — this is the instant DSL path. case graphDSLFailed(diagnostics: [Diagnostic], underlying: Error) 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)" case .graphDSLFailed(let diagnostics, let underlying): if diagnostics.isEmpty { return "graph DSL failed:\n\(underlying)" } let summary: String = diagnostics.map { diag -> String in let location: String = diag.line.map { "\($0):\(diag.column)" } ?? "?" return "\(location) \(diag.severity.rawValue): \(diag.message)" }.joined(separator: "\n") return "graph DSL failed:\n\(summary)" } } } #endif