# Stuck with this! function type cannot have an inferred error set

**URL:** <https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351>\
**Category:** Help\
**Tags:** language\
**Created:** [October 13, 2024, 1:43am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351 "2024-10-13T01:43:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hampterfuppinshire](https://ziggit.dev/user_avatar/ziggit.dev/hampterfuppinshire/32/3531_2.png) [@hampterfuppinshire](https://ziggit.dev/u/hampterfuppinshire)\
**Post date:** [October 13, 2024, 1:43am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351/1 "2024-10-13T01:43:32Z")

</div>

trying to have some base code setup:

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

// Define the explicit error set
pub const ObjectStorageError = error{
    FileNotFound,
    AccessDenied,
    OutOfMemory,
    InvalidInput,
};

pub const ObjectStorage = struct {
    // Explicitly specify the error set for each function pointer
    putIfAbsentFn: fn (self: *ObjectStorage, name: []const u8, bytes: []const u8) ObjectStorageError!void,
    listPrefixFn: fn (self: *ObjectStorage, prefix: []const u8, allocator: *std.mem.Allocator) ObjectStorageError!std.ArrayList([]const u8),
    readFn: fn (self: *ObjectStorage, name: []const u8, allocator: *std.mem.Allocator) ObjectStorageError![]const u8,

    pub fn putIfAbsent(self: *ObjectStorage, name: []const u8, bytes: []const u8) ObjectStorageError!void {
        return self.putIfAbsentFn(self, name, bytes);
    }

    pub fn listPrefix(self: *ObjectStorage, prefix: []const u8, allocator: *std.mem.Allocator) ObjectStorageError!std.ArrayList([]const u8) {
        return self.listPrefixFn(self, prefix, allocator);
    }

    pub fn read(self: *ObjectStorage, name: []const u8, allocator: *std.mem.Allocator) ObjectStorageError![]const u8 {
        return self.readFn(self, name, allocator);
    }
};

```

but keep getting the error `function type cannot have an inferred error set`

tried doing anyerror too, but can’t seem to get this work.

---

<div class="post-metadata">

**Author:** ![Travis](https://ziggit.dev/letter_avatar_proxy/v4/letter/t/bbce88/32.png) [@Travis](https://ziggit.dev/u/Travis)\
**Post date:** [October 13, 2024, 2:15am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351/2 "2024-10-13T02:15:38Z")

</div>

Hello and welcome. I think you’re might need to provide the actual code that’s failing. This code looks fine.

It seems like maybe you’re trying to write something like this elsewhere:

```zig
pub const Foo = struct {
    fn1: fn () !void,
};

```

Is that perhaps the case?

---

<div class="post-metadata">

**Author:** ![hampterfuppinshire](https://ziggit.dev/user_avatar/ziggit.dev/hampterfuppinshire/32/3531_2.png) [@hampterfuppinshire](https://ziggit.dev/u/hampterfuppinshire)\
**Post date:** [October 13, 2024, 2:18am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351/3 "2024-10-13T02:18:13Z")

</div>

Hey Travis, I am actually not running it btw! my bad?! it’s just having this code is showing an error in vscode. a red mark near the error set declaration.

---

<div class="post-metadata">

**Author:** ![Travis](https://ziggit.dev/letter_avatar_proxy/v4/letter/t/bbce88/32.png) [@Travis](https://ziggit.dev/u/Travis)\
**Post date:** [October 13, 2024, 2:20am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351/4 "2024-10-13T02:20:31Z")

</div>

Maybe try running it. zls can (rarely in my experience) get out of sync and might need a restart.

---

<div class="post-metadata">

**Author:** ![hampterfuppinshire](https://ziggit.dev/user_avatar/ziggit.dev/hampterfuppinshire/32/3531_2.png) [@hampterfuppinshire](https://ziggit.dev/u/hampterfuppinshire)\
**Post date:** [October 13, 2024, 2:27am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351/5 "2024-10-13T02:27:31Z")

</div>

it ran! sorry for being so dumb! thank you travis!

---

<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 13, 2024, 8:15am UTC](https://ziggit.dev/t/stuck-with-this-function-type-cannot-have-an-inferred-error-set/6351/6 "2024-10-13T08:15:35Z")

</div>

You are not dumb if you are trying to learn.

Don’t give up, keep at it, zig is new and still changing a lot, but it is worth the effort!
