Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › compiler/ › resinator/ › main.zig › cliDiagnosticsToErrorBundle
cliDiagnosticsToErrorBundle
main.cliDiagnosticsToErrorBundle
fn cliDiagnosticsToErrorBundle (
gpa : Allocator ,
diagnostics : *cli .Diagnostics ,
) !ErrorBundle
File
Code
fn cliDiagnosticsToErrorBundle (
gpa : Allocator ,
diagnostics : *cli .Diagnostics ,
) !ErrorBundle {
@branchHint (.cold );
var bundle : ErrorBundle .Wip = undefined ;
try bundle .init (gpa );
errdefer bundle .deinit ();
try bundle .addRootErrorMessage (.{
.msg = try bundle .addString ("invalid command line option(s)" ),
});
var cur_err : ?ErrorBundle .ErrorMessage = null ;
var cur_notes : std .ArrayList (ErrorBundle .ErrorMessage ) = .empty ;
defer cur_notes .deinit (gpa );
for (diagnostics .errors .items ) |err_details | {
switch (err_details .type ) {
.err => {
if (cur_err ) |err | {
try bundle .addRootErrorMessageWithNotes (err , cur_notes .items );
}
cur_err = .{
.msg = try bundle .addString (err_details .msg .items ),
};
cur_notes .clearRetainingCapacity ();
},
.warning => cur_err = null ,
.note => {
if (cur_err == null ) continue ;
cur_err .?.notes_len += 1 ;
try cur_notes .append (gpa , .{
.msg = try bundle .addString (err_details .msg .items ),
});
},
}
}
if (cur_err ) |err | {
try bundle .addRootErrorMessageWithNotes (err , cur_notes .items );
}
return try bundle .toOwnedBundle ("" );
}