Skip to content

std.debug.simple_panic

Standard libraryZig 0.17.0Official documentation
Sourcestd/debug/simple_panic.zig

Source line 1

This namespace is the default one used by the Zig compiler to emit various kinds of safety panics, due to the logic in std.builtin.panic.

Since Zig does not have interfaces, this file serves as an example template for users to provide their own alternative panic handling.

As an alternative, see std.debug.FullPanic.

std.debug.simple_panic.call

function

Source line 14

Prints the message to stderr without a newline and then traps.

Explicit calls to @panic lower to calling this function.

pub fn call(msg: []const u8, ra: ?usize) noreturn

Parameters

msg: []const u8
ra: ?usize

std.debug.simple_panic.castToNull

function

Source line 70

pub fn castToNull() noreturn

std.debug.simple_panic.copyLenMismatch

function

Source line 146

pub fn copyLenMismatch() noreturn

std.debug.simple_panic.corruptSwitch

function

Source line 126

pub fn corruptSwitch() noreturn

std.debug.simple_panic.divideByZero

function

Source line 111

pub fn divideByZero() noreturn

std.debug.simple_panic.exactDivisionRemainder

function

Source line 116

pub fn exactDivisionRemainder() noreturn

std.debug.simple_panic.forLenMismatch

function

Source line 141

pub fn forLenMismatch() noreturn

std.debug.simple_panic.inactiveUnionField

function

Source line 48

pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn

Parameters

accessed: @TypeOf(active)

std.debug.simple_panic.incorrectAlignment

function

Source line 75

pub fn incorrectAlignment() noreturn

std.debug.simple_panic.integerOutOfBounds

function

Source line 91

pub fn integerOutOfBounds() noreturn

std.debug.simple_panic.integerOverflow

function

Source line 96

pub fn integerOverflow() noreturn

std.debug.simple_panic.integerPartOutOfBounds

function

Source line 121

pub fn integerPartOutOfBounds() noreturn

std.debug.simple_panic.invalidEnumValue

function

Source line 136

pub fn invalidEnumValue() noreturn

std.debug.simple_panic.invalidErrorCode

function

Source line 80

pub fn invalidErrorCode() noreturn

std.debug.simple_panic.loadUninstantiableType

function

Source line 161

pub fn loadUninstantiableType() noreturn

std.debug.simple_panic.memcpyAlias

function

Source line 151

pub fn memcpyAlias() noreturn

std.debug.simple_panic.noreturnReturned

function

Source line 156

pub fn noreturnReturned() noreturn

std.debug.simple_panic.outOfBounds

function

Source line 34

pub fn outOfBounds(index: usize, len: usize) noreturn

Parameters

index: usize
len: usize

std.debug.simple_panic.reachedUnreachable

function

Source line 60

pub fn reachedUnreachable() noreturn

std.debug.simple_panic.sentinelMismatch

function

Source line 22

pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn

Parameters

found: @TypeOf(expected)

std.debug.simple_panic.shiftRhsTooBig

function

Source line 131

pub fn shiftRhsTooBig() noreturn

std.debug.simple_panic.shlOverflow

function

Source line 101

pub fn shlOverflow() noreturn

std.debug.simple_panic.shrOverflow

function

Source line 106

pub fn shrOverflow() noreturn

std.debug.simple_panic.sliceCastLenRemainder

function

Source line 54

pub fn sliceCastLenRemainder(src_len: usize) noreturn

Parameters

src_len: usize

std.debug.simple_panic.startGreaterThanEnd

function

Source line 41

pub fn startGreaterThanEnd(start: usize, end: usize) noreturn

Parameters

start: usize
end: usize

std.debug.simple_panic.std

alias

Source line 9

Alias of std

std.debug.simple_panic.unexpectedErrorCode

function

Source line 85

pub fn unexpectedErrorCode(err: anyerror) noreturn

Parameters

err: anyerror

std.debug.simple_panic.unwrapError

function

Source line 28

pub fn unwrapError(err: anyerror) noreturn

Parameters

err: anyerror

std.debug.simple_panic.unwrapNull

function

Source line 65

pub fn unwrapNull() noreturn
Source code

std/debug/simple_panic.zig

//! This namespace is the default one used by the Zig compiler to emit various
//! kinds of safety panics, due to the logic in `std.builtin.panic`.
//!
//! Since Zig does not have interfaces, this file serves as an example template
//! for users to provide their own alternative panic handling.
//!
//! As an alternative, see `std.debug.FullPanic`.

const std = @import("../std.zig");

/// Prints the message to stderr without a newline and then traps.
///
/// Explicit calls to `@panic` lower to calling this function.
pub fn call(msg: []const u8, ra: ?usize) noreturn {
    @branchHint(.cold);
    _ = ra;
    const stderr_writer = &std.debug.lockStderr(&.{}).file_writer.interface;
    stderr_writer.writeAll(msg) catch {};
    @trap();
}

pub fn sentinelMismatch(expected: anytype, found: @TypeOf(expected)) noreturn {
    @branchHint(.cold);
    _ = found;
    call("sentinel mismatch", null);
}

pub fn unwrapError(err: anyerror) noreturn {
    @branchHint(.cold);
    _ = &err;
    call("attempt to unwrap error", null);
}

pub fn outOfBounds(index: usize, len: usize) noreturn {
    @branchHint(.cold);
    _ = index;
    _ = len;
    call("index out of bounds", null);
}

pub fn startGreaterThanEnd(start: usize, end: usize) noreturn {
    @branchHint(.cold);
    _ = start;
    _ = end;
    call("start index is larger than end index", null);
}

pub fn inactiveUnionField(active: anytype, accessed: @TypeOf(active)) noreturn {
    @branchHint(.cold);
    _ = accessed;
    call("access of inactive union field", null);
}

pub fn sliceCastLenRemainder(src_len: usize) noreturn {
    @branchHint(.cold);
    _ = src_len;
    call("slice length does not divide exactly into destination elements", null);
}

pub fn reachedUnreachable() noreturn {
    @branchHint(.cold);
    call("reached unreachable code", null);
}

pub fn unwrapNull() noreturn {
    @branchHint(.cold);
    call("attempt to use null value", null);
}

pub fn castToNull() noreturn {
    @branchHint(.cold);
    call("cast causes pointer to be null", null);
}

pub fn incorrectAlignment() noreturn {
    @branchHint(.cold);
    call("incorrect alignment", null);
}

pub fn invalidErrorCode() noreturn {
    @branchHint(.cold);
    call("invalid error code", null);
}

pub fn unexpectedErrorCode(err: anyerror) noreturn {
    @branchHint(.cold);
    _ = err;
    call("unexpected error code", null);
}

pub fn integerOutOfBounds() noreturn {
    @branchHint(.cold);
    call("integer does not fit in destination type", null);
}

pub fn integerOverflow() noreturn {
    @branchHint(.cold);
    call("integer overflow", null);
}

pub fn shlOverflow() noreturn {
    @branchHint(.cold);
    call("left shift overflowed bits", null);
}

pub fn shrOverflow() noreturn {
    @branchHint(.cold);
    call("right shift overflowed bits", null);
}

pub fn divideByZero() noreturn {
    @branchHint(.cold);
    call("division by zero", null);
}

pub fn exactDivisionRemainder() noreturn {
    @branchHint(.cold);
    call("exact division produced remainder", null);
}

pub fn integerPartOutOfBounds() noreturn {
    @branchHint(.cold);
    call("integer part of floating point value out of bounds", null);
}

pub fn corruptSwitch() noreturn {
    @branchHint(.cold);
    call("switch on corrupt value", null);
}

pub fn shiftRhsTooBig() noreturn {
    @branchHint(.cold);
    call("shift amount is greater than the type size", null);
}

pub fn invalidEnumValue() noreturn {
    @branchHint(.cold);
    call("invalid enum value", null);
}

pub fn forLenMismatch() noreturn {
    @branchHint(.cold);
    call("for loop over objects with non-equal lengths", null);
}

pub fn copyLenMismatch() noreturn {
    @branchHint(.cold);
    call("source and destination have non-equal lengths", null);
}

pub fn memcpyAlias() noreturn {
    @branchHint(.cold);
    call("@memcpy arguments alias", null);
}

pub fn noreturnReturned() noreturn {
    @branchHint(.cold);
    call("'noreturn' function returned", null);
}

pub fn loadUninstantiableType() noreturn {
    call("attempt to load uninstantiable type", null);
}