You CAN do error payloads in zig

Поделиться
HTML-код
  • Опубликовано: 6 май 2024
  • How I do Error Payloads in Zig.
    This is a response to chat in @ThePrimeagen 's video on Zig
    • Is 2024 The Year Of Zig ?
    Article covering the same subject:
    zig.news/ityonemo/sneaky-erro...

Комментарии • 7

  • @JacobDanton
    @JacobDanton 12 дней назад +4

    I appreciate the workaround, but that’s all it is. With this approach you:
    * can return an error without setting an error payload
    * can set an error payload without returning an error
    * do not have error payload types associated with the error and are tied to one type for all errors
    But I believe there is a GitHub issue where the Zig maintainers agreed they are adding error payloads eventually.

  • @iatheman
    @iatheman 6 дней назад

    The machine code responding to the payload needs is great and all. But writing and reading this kind of code isn't the best experience. I'd rather have payloads embedded in the error types if possible.

  • @CoolestPossibleName
    @CoolestPossibleName 21 день назад

    I was watching that primeagen's on youtube, read that chat, and saw this video.
    The explanation you did with godbolt was great.
    Personally I think error payload is just unnecessary, at least in this particular example. The users of the function could read the document, understand the error better and handle it the way they want it. This feels like too much work.

    • @isaacyonemoto
      @isaacyonemoto 20 дней назад +4

      Agreed. too much for this example but if I made a "real-ish" example it would be too much code for a 10 minute video 😂
      Imagine though for a parser, you could stash file/line/column in the payload.

    • @nathanfranck5822
      @nathanfranck5822 13 дней назад +4

      I ran into an issue recently where I wanted to get an error payload when parsing JSON. The std library in zig does have a way to get info about where the json parser failed though, so you can still extract something meaningful to dump in a log or on-screen, it's just not super convenient.
      Definitely most cases where you're getting an error, there's not going to be any meaningful payload that needs to be scraped together at runtime, and not having it as a convenient feature might prevent extra memory leaks when you're off the happy path... But it still seems a bit strange to not have it when tagged unions in zig already exist.

    • @codechapin
      @codechapin 9 дней назад

      @@nathanfranck5822is there a way to get logging from the std library?

  • @salim444
    @salim444 16 дней назад

    I searched for this video