# Assert but only in paranoid mode

**URL:** <https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934>\
**Category:** Explain\
**Created:** [May 2, 2025, 12:59pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934 "2025-05-02T12:59:26Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [May 31, 2025, 1:01pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/21 "2025-05-31T13:01:09Z")

</div>

Ha, i like the catch unreachable because that’s really a oneliner.  
And yes, my tech\_check is meant as an assert. A lowlevel miles deep bits and bytes logic bug catch, which should never ever happen.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [May 31, 2025, 1:04pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/22 "2025-05-31T13:04:42Z")

</div>

The function is called somehow in releasemode. no `catch unreachable` possible.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2025, 1:15pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/23 "2025-05-31T13:15:48Z")

</div>

if you’re talking about `tech_check` ofc it is there is no logic stopping it from being called in fast or small modes.  
you need to add that yourself, unfortunately zig doesnt have a way to get if runtime safety is on or off, which would be much better than checking the build mode.

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [May 31, 2025, 1:19pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/24 "2025-05-31T13:19:46Z")

</div>

Yeah I added some stuff to be absolutely sure.

```zig
pub inline fn not_in_releasemode() void
{
    comptime if (is_release) @compileError("Don't do this in release mode");
}

pub fn isOk(error_union: anytype) bool
{
    not_in_releasemode();
    return !std.meta.isError(error_union);
}

```

```zig
pub fn tech_check(...) BoardError!void
{
    lib.not_in_releasemode();
    // do stuff..
}

```

and use it like this:

```zig
 assert(lib.isOk(tech_check(...));

```

edit: unfortunately I don’t get any info on which error occurred. anyway… the assert question is solved for me.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2025, 1:27pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/25 "2025-05-31T13:27:35Z")

</div>

> [@ericlang](#):
>
> unfortunately I don’t get any info on which error occurred

you should get an error trace, though it will be less helpful in release safe as there is less debug info

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [May 31, 2025, 1:31pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/26 "2025-05-31T13:31:21Z")

</div>

the error trace in debugmode stops at assert. But in my is\_ok I can get the info.

```zig
thread 1752 panic: reached unreachable code
C:\zig\zig-windows-x86_64-0.14.0\lib\std\debug.zig:522:14: 0x7ff697b2917d in assert (main.exe.obj)
    if (!ok) unreachable; // assertion failure
             ^
C:\Data\zig\scrabble\src\tests.zig:119:15: 0x7ff697ba39d0 in test_movegenerator (main.exe.obj)
        assert(lib.is_ok(board.tech_check(mapping)));
              ^
C:\Data\zig\scrabble\src\main.zig:89:38: 0x7ff697ba4ffb in main (main.exe.obj)
    try uses.tests.test_movegenerator(&graph);
                                     ^
C:\zig\zig-windows-x86_64-0.14.0\lib\std\start.zig:475:53: 0x7ff697ba526f in WinStartup (main.exe.obj)
    std.os.windows.ntdll.RtlExitUserProcess(callMain());

```

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2025, 1:33pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/27 "2025-05-31T13:33:31Z")

</div>

ah it will probably be more helpful if you use `catch unreachable`

edit: it doesnt have a error trace at all, thats just the stack trace, probably cause it doesnt know its cause by an error

---

<div class="post-metadata">

**Author:** ![ericlang](https://ziggit.dev/user_avatar/ziggit.dev/ericlang/32/8515_2.png) [@ericlang](https://ziggit.dev/u/ericlang)\
**Post date:** [May 31, 2025, 1:43pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/28 "2025-05-31T13:43:12Z")

</div>

true… i never fetched an error trace. will look for its what and how

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [May 31, 2025, 1:45pm UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/29 "2025-05-31T13:45:12Z")

</div>

you dont need to get the error trace yourself the compiler should give you with `catch unreachable`.

though you could if you wanted…

---

<div class="post-metadata">

**Author:** ![mnemnion](https://ziggit.dev/user_avatar/ziggit.dev/mnemnion/32/2478_2.png) [@mnemnion](https://ziggit.dev/u/mnemnion)\
**Post date:** [June 1, 2025, 12:47am UTC](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934/30 "2025-06-01T00:47:57Z")

</div>

> [@vulpesx](#):
>
> you dont need to get the error trace yourself the compiler should give you with `catch unreachable`.

But you can get it with `@errorReturnTrace`, if you want it.

[Previous page](https://ziggit.dev/t/assert-but-only-in-paranoid-mode/9934.md?page=1)
