Introduce CompilerDiagnostic and CompileFailure so callers can pretty-print TypeScript errors in the frida-tools format (path:line:character - category TS<code>: text). Tracer hooks and custom-instrument compiles rewrite the on-disk path to the user-facing display name. Also fix a race in withCompilerDiagnostics: the events subscriber was racing with esbuild's signals and could miss .finished on fast failures, hanging the caller. Pre-create the stream and await the events task.
39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
import Frida
|
|
|
|
extension Frida.Error: @retroactive CustomStringConvertible {}
|
|
|
|
extension InstrumentStatus {
|
|
public static func from(error: Swift.Error, kind: FailureKind) -> InstrumentStatus {
|
|
let (message, stack) = describe(error)
|
|
switch kind {
|
|
case .load:
|
|
return .loadFailed(message: message, stack: stack)
|
|
case .reload:
|
|
return .reloadFailed(message: message, stack: stack)
|
|
case .configInvalid:
|
|
return .configInvalid(message: message, stack: stack)
|
|
}
|
|
}
|
|
|
|
public enum FailureKind: Sendable {
|
|
case load
|
|
case reload
|
|
case configInvalid
|
|
}
|
|
|
|
private static func describe(_ error: Swift.Error) -> (message: String, stack: String?) {
|
|
if let compile = error as? CompileFailure {
|
|
let inner = describe(compile.underlying)
|
|
var parts = compile.diagnostics.map(\.description)
|
|
if let stack = inner.stack { parts.append(stack) }
|
|
return (inner.message, parts.isEmpty ? nil : parts.joined(separator: "\n"))
|
|
}
|
|
if let rpc = error as? Frida.Error,
|
|
case let .rpcError(message: message, stackTrace: stackTrace) = rpc
|
|
{
|
|
return (message, stackTrace)
|
|
}
|
|
return (String(describing: error), nil)
|
|
}
|
|
}
|