Arnau478 / hevi

Hex viewer
https://arnau478.github.io/hevi/
GNU General Public License v3.0
56 stars 2 forks source link

hevi doesn't print anything on `error.InvalidConfig` #26

Closed Reokodoku closed 2 months ago

Reokodoku commented 2 months ago

hevi version: 1.0.0-dev.52+d975b28bdc (latest commit) Zig version: 0.13.0-dev.75+5c9eb4081 OS: Linux

I don't know if it's my problem, zig's problem, or hevi's problem, but when I have an invalid JSON config file the program doesn't print anything.

But if I check with strace ./hevi hevi I can found this

write(2, "error: InvalidConfig\n", 21)  = -1 EBADF
[...]
write(2, "Unable to dump stack trace: ", 28) = -1 EBADF

on Debug or

write(2, "error: InvalidConfig\n", 21)  = -1 EBADF

on Release*.

Affected builds (that I tried):

Config file:

{
    "color": true,
    "parser": "data",
}
Arnau478 commented 2 months ago

Yeah, I noticed that too... I've tried a few things, and:

I'm starting to think it's a compiler bug, but I want to make sure before opening an issue there.

Reokodoku commented 2 months ago

Maybe this happens when a try fails. For example if you do strace ./hevi --version you get

[...]
write(2, "hevi ", 5hevi )                    = 5
write(2, "1", 11)                        = 1
write(2, ".", 1.)                        = 1
write(2, "0", 10)                        = 1
write(2, ".", 1.)                        = 1
write(2, "0", 10)                        = 1
write(2, "-", 1-)                        = 1
write(2, "dev.52", 6dev.52)                   = 6
write(2, "+", 1+)                        = 1
write(2, "d975b28bdc", 10d975b28bdc)              = 10
write(2, "\n", 1
)                       = 1

It writes to stderr like error.InvalidConfig but here the write is successful. Same thing for strace ./hevi --help

Arnau478 commented 2 months ago

Yeah, that's really weird... Specially the fact that the error code is EBADF (bad file descriptor)... Isn't FD 2 always available?

At this point this is for sure a compiler bug. Maybe we should open an issue over there.

Arnau478 commented 2 months ago

Okay, so I found a close(2) syscall before the write(2, ...) syscall, and it was a pretty dumb mistake. https://github.com/Arnau478/hevi/blob/c6c30b876ce551aff20f0fa23177a5f63f9f9011/src/options.zig#L49