feature. See also
. The project being documented here (as the example) is the Zig library itself.
main.ErrorHandler
const ErrorHandler = union(enum)
File
Code
const ErrorHandler = union(enum) {
server: std.zig.Server,
stderr,
pub fn emitCliDiagnostics(
self: *ErrorHandler,
allocator: Allocator,
io: Io,
args: []const []const u8,
diagnostics: *cli.Diagnostics,
) !void {
switch (self.*) {
.server => |*server| {
var error_bundle = try cliDiagnosticsToErrorBundle(allocator, diagnostics);
defer error_bundle.deinit(allocator);
try server.serveErrorBundle(error_bundle);
},
.stderr => return diagnostics.renderToStderr(io, args),
}
}
pub fn emitAroDiagnostics(
self: *ErrorHandler,
allocator: Allocator,
fail_msg: []const u8,
comp: *aro.Compilation,
) !void {
const io = comp.io;
switch (self.*) {
.server => |*server| {
var error_bundle = try compiler_util.aroDiagnosticsToErrorBundle(
comp.diagnostics,
allocator,
fail_msg,
);
defer error_bundle.deinit(allocator);
try server.serveErrorBundle(error_bundle);
},
.stderr => {
const stderr = try io.lockStderr(&.{}, null);
defer io.unlockStderr();
try renderErrorMessage(stderr.terminal(), .err, "{s}", .{fail_msg});
},
}
}
pub fn emitDiagnostics(
self: *ErrorHandler,
allocator: Allocator,
io: Io,
cwd: Io.Dir,
source: []const u8,
diagnostics: *Diagnostics,
mappings: SourceMappings,
) !void {
switch (self.*) {
.server => |*server| {
var error_bundle = try diagnosticsToErrorBundle(allocator, source, diagnostics, mappings);
defer error_bundle.deinit(allocator);
try server.serveErrorBundle(error_bundle);
},
.stderr => return diagnostics.renderToStderr(io, cwd, source, mappings),
}
}
pub fn emitMessage(
self: *ErrorHandler,
allocator: Allocator,
io: Io,
msg_type: @import("utils.zig").ErrorMessageType,
comptime format: []const u8,
args: anytype,
) !void {
switch (self.*) {
.server => |*server| {
if (msg_type != .err) return;
var error_bundle = try errorStringToErrorBundle(allocator, format, args);
defer error_bundle.deinit(allocator);
try server.serveErrorBundle(error_bundle);
},
.stderr => {
const stderr = try io.lockStderr(&.{}, null);
defer io.unlockStderr();
try renderErrorMessage(stderr.terminal(), msg_type, format, args);
},
}
}
}