# "attempt to use null value" when doing zig build run inside emacs compilation mode or shell command

**URL:** <https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908>\
**Category:** Help\
**Tags:** build-system\
**Created:** [October 10, 2026, 11:20am UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908 "2026-10-10T11:20:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Psimonk](https://ziggit.dev/user_avatar/ziggit.dev/psimonk/32/9752_2.png) [@Psimonk](https://ziggit.dev/u/Psimonk)\
**Post date:** [October 10, 2026, 11:20am UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/1 "2026-10-10T11:20:39Z")

</div>

Hi, I use emacs when coding and frequently use the built in compilation mode for compiling and running my code. I recently ran into an issue when trying to build using this compilation mode on 0.17.0. When running `zig build run` inside a normal terminal things work as expected, but when running `zig build run` inside emacs i get the error:

```zig
thread 7098 panic: attempt to use null value

```

Doesn’t seem to matter if i use compilation mode or the shell command keybind, the same issue appears, and when running the same command in konsole the project builds as expected.

I haven’t been on linux for a while, but I don’t remember this being an issue in 0.16.0

 ![Screenshot_20261010_131331](https://ziggit.dev/uploads/default/original/2X/0/007b79e9369da8dc2ac3a288e0a7062b6227a7dc.png)  
 ![Screenshot_20261010_131431](https://ziggit.dev/uploads/default/original/2X/0/06fdce2f03155312d5606ee0bbb17038e7658798.png)

---

<div class="post-metadata">

**Author:** ![SpinTensor](https://ziggit.dev/user_avatar/ziggit.dev/spintensor/32/2942_2.png) [@SpinTensor](https://ziggit.dev/u/SpinTensor)\
**Post date:** [October 10, 2026, 11:33am UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/2 "2026-10-10T11:33:33Z")

</div>

This sounds like you used an optional without testing for null. Like `a=b.?;` where b is the optional.  
Better to check for it explicitly:

```zig
if (b) |val| {
    a = val;
} else ...
```

---

<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:** [October 10, 2026, 12:14pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/3 "2026-10-10T12:14:22Z")

</div>

Nah the panic is in the build system, otherwise there would be something like

`step foo returned error code 1: [insert stderr from foo]`

And if the issue was in the configure phase (`build.zig`) then there should be a stacktrace as it is build in debug mode.

So the issue is probably a regression in the maker split. I did a quick look but I can’t find anything obvious.

@Psimonk run the command with `ZIG_DEBUG_CMD=1` to build the maker in debug mode to get more info.

---

<div class="post-metadata">

**Author:** ![Psimonk](https://ziggit.dev/user_avatar/ziggit.dev/psimonk/32/9752_2.png) [@Psimonk](https://ziggit.dev/u/Psimonk)\
**Post date:** [October 10, 2026, 12:14pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/4 "2026-10-10T12:14:59Z")

</div>

My build.zig:

```zig
const std = @import("std");

const Translator = @import("translate_c").Translator;

pub fn build(b: *std.Build) void {
    const includePath = b.option([]const u8, "include", "Specify include path.");
    const libPath = b.option([]const u8, "lib", "Specify lib path.");

    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const glMod = b.createModule(.{
        .root_source_file = b.path("src/gl.zig"),
        .target = target,
        .optimize = optimize,
    });

    // Linking OpenGL differs between Windows and Linux.
    switch (target.result.os.tag) {
        .linux => {
            glMod.linkSystemLibrary("GL", .{});
        },
        .windows => {
            glMod.linkSystemLibrary("opengl32", .{});
        },
        else => {},
    }

    const translate_c = b.dependency("translate_c", .{
        .target = target,
        .optimize = optimize,
    });

    // SDL2
    const sdlTranslate = Translator.init(translate_c, .{
        .c_source_file = b.path("src/c/sdl.h"),
        .target = target,
        .optimize = optimize,
        .link_system_libs = &.{
            .{ .name = "SDL2" },
        },
    });

    if (includePath) |path| {
        sdlTranslate.addIncludePath(.{ .cwd_relative = path });
    }

    if (libPath) |path| {
        sdlTranslate.mod.addLibraryPath(.{ .cwd_relative = path });
    }

    // stb_image.h
    const stbiTranslate = Translator.init(translate_c, .{
        .c_source_file = b.path("src/c/stb_image.h"),
        .target = target,
        .optimize = optimize,
    });

    stbiTranslate.mod.addCSourceFile(.{
        .file = b.path("src/c/stbi.c"),
        .flags = &.{"-std=c99"},
    });

    // Main exe
    const exe = b.addExecutable(.{
        .name = "ziggin",
        .root_module = b.createModule(
            .{
                .root_source_file = b.path("src/main.zig"),
                .target = target,
                .optimize = optimize,
                .imports = &.{
                    .{
                        .name = "gl",
                        .module = glMod,
                    },
                    .{
                        .name = "sdl",
                        .module = sdlTranslate.mod,
                    },
                    .{
                        .name = "stbi",
                        .module = stbiTranslate.mod,
                    },
                },
            },
        ),
    });

    // Use -mwindows when building in release mode.
    if (target.result.os.tag == .windows and optimize != .debug) {
        exe.subsystem = .windows;
    }

    b.installArtifact(exe);

    const run_step = b.step("run", "Run the app");

    const run_cmd = b.addRunArtifact(exe);
    run_step.dependOn(&run_cmd.step);
    run_cmd.step.dependOn(b.getInstallStep());
}

```

Do I really need to handle for null here?

```zig
if (includePath) |path| {
    sdlTranslate.addIncludePath(.{ .cwd_relative = path });
}

if (libPath) |path| {
    sdlTranslate.mod.addLibraryPath(.{ .cwd_relative = path });
}

```

It doesn’t resolve to false in the if statement when they are unset?

---

<div class="post-metadata">

**Author:** ![Psimonk](https://ziggit.dev/user_avatar/ziggit.dev/psimonk/32/9752_2.png) [@Psimonk](https://ziggit.dev/u/Psimonk)\
**Post date:** [October 10, 2026, 12:19pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/5 "2026-10-10T12:19:39Z")

</div>

This is what happens when doing it that way:

 ![Screenshot_20261010_141753](https://ziggit.dev/uploads/default/original/2X/4/4a7254ca4f2fb640330e2282a10e240cd8353b9a.png)  
 ![Screenshot_20261010_141916](https://ziggit.dev/uploads/default/original/2X/d/dfca279e499692ae34d0a0cb1c3e64442789ea28.png)

---

<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:** [October 10, 2026, 12:24pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/6 "2026-10-10T12:24:43Z")

</div>

> [@Psimonk](#):
>
> Do I really need to handle for null here?
> 
> ```zig
> if (includePath) |path| {
> sdlTranslate.addIncludePath(.{ .cwd_relative = path });
> }
> 
> if (libPath) |path| {
> sdlTranslate.mod.addLibraryPath(.{ .cwd_relative = path });
> }
> 
> ```
> 
> It doesn’t resolve to false in the if statement when they are unset?

No this seems fine, though it is weird but I don’t think its relevant to the issue.

> [@Psimonk](#):
>
> This is what happens when doing it that way:

This is quite weird; unfortunately it is quite late for me so I can’t dig into it at the moment.

---

<div class="post-metadata">

**Author:** ![gonzo](https://ziggit.dev/user_avatar/ziggit.dev/gonzo/32/54_2.png) [@gonzo](https://ziggit.dev/u/gonzo)\
**Post date:** [October 10, 2026, 1:56pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/7 "2026-10-10T13:56:07Z")

</div>

Maybe the zig cache is corrupted?

---

<div class="post-metadata">

**Author:** ![jmstevers](https://ziggit.dev/user_avatar/ziggit.dev/jmstevers/32/9230_2.png) [@jmstevers](https://ziggit.dev/u/jmstevers)\
**Post date:** [October 10, 2026, 2:18pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/8 "2026-10-10T14:18:05Z")

</div>

Can confirm. I’ve been getting this crash recently and deleting the cache fixes it for me

---

<div class="post-metadata">

**Author:** ![Psimonk](https://ziggit.dev/user_avatar/ziggit.dev/psimonk/32/9752_2.png) [@Psimonk](https://ziggit.dev/u/Psimonk)\
**Post date:** [October 10, 2026, 2:22pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/9 "2026-10-10T14:22:12Z")

</div>

Just tried deleting the projects local cache as well as `~/.cache/zig`, sadly still getting the same issue

---

<div class="post-metadata">

**Author:** ![rissw](https://ziggit.dev/user_avatar/ziggit.dev/rissw/32/5093_2.png) [@rissw](https://ziggit.dev/u/rissw)\
**Post date:** [October 10, 2026, 2:51pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/10 "2026-10-10T14:51:52Z")

</div>

should it be `.zig-cache` ?

---

<div class="post-metadata">

**Author:** ![Psimonk](https://ziggit.dev/user_avatar/ziggit.dev/psimonk/32/9752_2.png) [@Psimonk](https://ziggit.dev/u/Psimonk)\
**Post date:** [October 10, 2026, 4:05pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/11 "2026-10-10T16:05:54Z")

</div>

That’s the project local cache, i did delete that as well.

---

<div class="post-metadata">

**Author:** ![raddari](https://ziggit.dev/user_avatar/ziggit.dev/raddari/32/991_2.png) [@raddari](https://ziggit.dev/u/raddari)\
**Post date:** [October 10, 2026, 5:43pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/12 "2026-10-10T17:43:08Z")

</div>

What’s the output for `zig version` and `zig env` in emacs vs konsole? If they don’t match, that could be a lead.

---

<div class="post-metadata">

**Author:** ![Psimonk](https://ziggit.dev/user_avatar/ziggit.dev/psimonk/32/9752_2.png) [@Psimonk](https://ziggit.dev/u/Psimonk)\
**Post date:** [October 10, 2026, 6:43pm UTC](https://ziggit.dev/t/attempt-to-use-null-value-when-doing-zig-build-run-inside-emacs-compilation-mode-or-shell-command/17908/13 "2026-10-10T18:43:52Z")

</div>

From what I can tell they match, here is zig env:

```zig
[simon@simon-linux ziggin]$ zig env
.{
    .zig_exe = "/home/simon/.local/bin/zig/zig",
    .lib_dir = "/home/simon/.local/bin/zig/lib",
    .std_dir = "/home/simon/.local/bin/zig/lib/std",
    .global_cache_dir = "/home/simon/.cache/zig",
    .version = "0.17.0",
    .target = "x86_64-linux.7.2.9...7.2.9-gnu.2.44",
    .env = .{
        .ZIG_GLOBAL_CACHE_DIR = null,
        .ZIG_LOCAL_CACHE_DIR = null,
        .ZIG_LOCAL_PKG_DIR = null,
        .ZIG_LIB_DIR = null,
        .ZIG_LIBC = null,
        .ZIG_BUILD_ERROR_STYLE = null,
        .ZIG_BUILD_MULTILINE_ERRORS = null,
        .ZIG_BUILD_SUMMARY = null,
        .ZIG_VERBOSE_LINK = null,
        .ZIG_VERBOSE_CC = null,
        .ZIG_VERBOSE_CMD = null,
        .ZIG_DEBUG_CMD = null,
        .ZIG_IS_DETECTING_LIBC_PATHS = null,
        .ZIG_IS_AVOIDING_CALLING_ITSELF = null,
        .NIX_CFLAGS_COMPILE = null,
        .NIX_CFLAGS_LINK = null,
        .NIX_LDFLAGS = null,
        .C_INCLUDE_PATH = null,
        .CPLUS_INCLUDE_PATH = null,
        .LIBRARY_PATH = null,
        .CC = null,
        .PKG_CONFIG = null,
        .NO_COLOR = null,
        .CLICOLOR_FORCE = null,
        .XDG_CACHE_HOME = null,
        .LOCALAPPDATA = null,
        .HOME = "/home/simon",
        .PROGRAMDATA = null,
        .HOMEBREW_PREFIX = null,
    },
}

```
