# Weird error with std.debug.print + "-freference" not working

**URL:** <https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653>\
**Category:** Help\
**Tags:** zig-0-15-1\
**Created:** [August 23, 2025, 8:55pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653 "2025-08-23T20:55:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![bunxen](https://ziggit.dev/user_avatar/ziggit.dev/bunxen/32/4640_2.png) [@bunxen](https://ziggit.dev/u/bunxen)\
**Post date:** [August 23, 2025, 8:55pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/1 "2025-08-23T20:55:39Z")

</div>

Hi, I’m not really sure where to talk about this.

I figured it out but while doing ziglings I had this error:

```zig
Compiling: 058_quiz7.zig
error: the following command failed with 1 compilation errors:
zig-x86_64-linux-0.15.1/zig build-exe /ziglings/exercises/058_quiz7.zig --cache-dir ziglings/.zig-cache --listen=-
zig-x86_64-linux-0.15.1/lib/std/Io/Writer.zig:1120:51: error: expected type '[]const u8', found '*const 058_quiz7.Place'
                        const slice: []const u8 = value;
                                                  ^ ~~~~
referenced by:
    print__anon_22980: zig-x86_64-linux-0.15.1/lib/std/Io/Writer.zig:700:25
    print__anon_22916: zig-x86_64-linux-0.15.1/lib/std/debug.zig:231:23
    8 reference(s) hidden; use '-freference-trace=10' to see all references

```

I couldn’t use the `-freference-trace=10` flag, it wouldn’t change the output, so I was a little lost.

Turned out I was just using the structs directly instead of using a value.

```zig
.place => |place| print("{s}", .{place}),
.path => |path| print("--{}->", .{path}),

```

instead of

```zig
.place => |place| print("{s}", .{place.name}),
.path => |path| print("--{}->", .{path.dist}),

```

This error didn’t appear until I fixed the other errors so I didn’t think immediately about the prints at the very beginning.

Are these bugs?  
Is the flag not working because of how ziglings is built? if so how can I dig deeper in the trace?

---

<div class="post-metadata">

**Author:** ![hvbargen](https://ziggit.dev/user_avatar/ziggit.dev/hvbargen/32/5696_2.png) [@hvbargen](https://ziggit.dev/u/hvbargen)\
**Post date:** [August 23, 2025, 9:46pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/2 "2025-08-23T21:46:54Z")

</div>

Not a bug.

It’s just that in case of errors in formatting (typically in calls to std.debug.print and the like), the error messages of the compiler are absolutely not helpful, in particular because they point into the std lib and not to the corresponding line of your own program.

Personally, I consider this the biggest downside of Zig.

Practically all other error messages of the compiler are useful.

I hope that one day the error message will be improved.

Zig has enough upsides which outweigh this confusing messages, so I learned to just accept it and be very careful with formatting.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [August 23, 2025, 10:59pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/3 "2025-08-23T22:59:40Z")

</div>

This isn’t true at all, in normal cases passing `-freference-trace` will give you either very many or unlimited number of reference traces (not sure which) and then you just need to look at the files to spot the first one that is actually within your code.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [August 23, 2025, 11:03pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/4 "2025-08-23T23:03:00Z")

</div>

I think it is likely that @bunxen is using the default way to run ziglings and it seems that that doesn’t pass the reference-trace argument for some reason, I think it is likely that there would be some way to improve the ziglings `build.zig` so that it works. Would need to look into it a bit more.

For now it should be possible to instead run it directly, based on:

> [@bunxen](#):
>
> ```zig
> zig-x86_64-linux-0.15.1/zig build-exe /ziglings/exercises/058_quiz7.zig --cache-dir ziglings/.zig-cache --listen=-
> ``
> 
> ```

Try this:

```zig
zig run /ziglings/exercises/058_quiz7.zig -freference-trace

```

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [August 23, 2025, 11:20pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/5 "2025-08-23T23:20:58Z")

</div>

Hmm I think ziglings still runs on an older dev version of Zig?

---

<div class="post-metadata">

**Author:** ![bunxen](https://ziggit.dev/user_avatar/ziggit.dev/bunxen/32/4640_2.png) [@bunxen](https://ziggit.dev/u/bunxen)\
**Post date:** [August 23, 2025, 11:21pm UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/6 "2025-08-23T23:21:14Z")

</div>

I see, thank you I tried with `run` and it did allow for showing more of the trace

also I read a little that this is because it’s a type error, I’m not sure I grasp the nuance but yeah I’ll just be careful of format stuff

---

<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:** [August 24, 2025, 12:33am UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/7 "2025-08-24T00:33:14Z")

</div>

The `{s}` expects a slice of bytes, or something that can coerce to that, that’s what the assignment the error is coming from is for. But your type can’t coerce to that so you get a type error.

---

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [August 24, 2025, 1:19am UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/8 "2025-08-24T01:19:29Z")

</div>

So within `build.zig` there is this within the `compile` function:

```zig
        const cmd = switch (self.exercise.kind) {
            .exe => "build-exe",
            .@"test" => "test",
        };
        zig_args.append(cmd) catch @panic("OOM");

        // Enable C support for exercises that use C functions.
        if (self.exercise.link_libc) {
            zig_args.append("-lc") catch @panic("OOM");
        }

        // NOTE I added this if below to forward the -freference-trace
        // NOTE passed to: zig build -freference-trace
        // NOTE to the command that compiles the exercise
        if (b.reference_trace) |rt| {
            zig_args.append(b.fmt("-freference-trace={}", .{rt})) catch @panic("OOM");
        }

```

I created a pull request here: [#294 - pass -freference-trace to executed compile command - ziglings/exercises - Codeberg.org](https://codeberg.org/ziglings/exercises/pulls/294)

---

<div class="post-metadata">

**Author:** ![hvbargen](https://ziggit.dev/user_avatar/ziggit.dev/hvbargen/32/5696_2.png) [@hvbargen](https://ziggit.dev/u/hvbargen)\
**Post date:** [August 24, 2025, 4:05am UTC](https://ziggit.dev/t/weird-error-with-std-debug-print-freference-not-working/11653/9 "2025-08-24T04:05:11Z")

</div>

Thanks for this info.

Actually `-freference-trace` never caught my eye.  
And (not tried yet myself) from some output examples, it seems that it would help, but at the price of adding a lot of verbosity to the output, which probably is the reason why this option is not enabled by default.

+1 for @Vexu’s proposal in

> <https://github.com/ziglang/zig/issues/12093#issuecomment-1585340480>
>
> \## Why?
> 
> With #12044 compile error notes can now be printed more compactly ena…bling long, multi sentence errors to be broken down into the main error, the reason for the error, and suggestions for what to do about it. I think generic interface validation for example could also benefit from this with \`hash\_map.zig\` being a good example:
> https://github.com/ziglang/zig/blob/7090f0471c0169c60a9476b537b09eebe1bdf6af/lib/std/hash\_map.zig#L17-L22 
> 
> \## How?
> 
> Syntax suggestions include:
> 1. making it variadic \`@compileError(err: \[\]const u8, ...)\` 
> \* this has all the same issues as regular variadic function in that comptime logic can't control how many notes there are
> 2. adding a note list parameter \`@compileError(err: \[\]const u8, notes: \[\]const \[\]const u8)\`
> \* this breaks all existing usage, most of which won't even need notes
> 3. adding a second optional note list paramter \`@compileError(err: \[\]const u8, ...)\`
> \* same as above but the function is variadic so the second parameter can be omitted
> \* this is my favorite
> 4. adding a new builtin specifically for this use case \`@compileErrorWithNotes(err: \[\]const u8, notes: \[\]const \[\]const u8)\`

Given how much time already was spent on helping users individually over the years, explaining what they did wrong in these cases of unhelpful error messages and how to find out where, I think actually solving this once and for all would be a good idea.
