Skip to content

Commit

Permalink
[progress #146] removing custom errors done
Browse files Browse the repository at this point in the history
  • Loading branch information
tiawl committed Apr 8, 2024
1 parent ccc8a21 commit 6eda750
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
20 changes: 4 additions & 16 deletions src/options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,6 @@ pub const Options = struct
colors: colors_options = colors_options {},
stars: stars_options = stars_options {},

const OptionsError = error
{
NoExecutableName,
MissingArgument,
UnknownOption,
UnknownArgument,
ZeroIntegerArgument,
OverflowArgument,
Help,
Version,
};

fn usage_help (self: *@This ()) void
{
_ = self;
Expand Down Expand Up @@ -229,7 +217,7 @@ pub const Options = struct
} else {
try logger.app (.ERROR, "unknown option: '{s}'", .{ options.items [index] });
self.usage ();
return OptionsError.UnknownOption;
return error.UnknownOption;
}

index += 1;
Expand Down Expand Up @@ -258,7 +246,7 @@ pub const Options = struct

_ = options_iterator.next () orelse
{
return OptionsError.NoExecutableName;
return error.NoExecutableName;
};

var options = std.ArrayList ([] const u8).init (logger.allocator.*);
Expand All @@ -274,10 +262,10 @@ pub const Options = struct
if (self.help)
{
self.usage ();
return OptionsError.Help;
return error.Help;
} else if (self.version) {
Logger.version ();
return OptionsError.Version;
return error.Version;
}

self.fix_random ();
Expand Down
17 changes: 4 additions & 13 deletions src/vk/context.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ pub const Context = struct
vk.KHR.SWAPCHAIN,
};

const ContextError = error
{
NoDevice,
NoSuitableDevice,
NoSuitableMemoryType,
ImageAcquireFailed,
NoAvailableFilename,
};

logger: *const Logger = undefined,
instance: instance_vk = undefined,
surface: vk.KHR.Surface = undefined,
Expand Down Expand Up @@ -665,7 +656,7 @@ pub const Context = struct
try vk.PhysicalDevices.enumerate (self.instance.instance, &device_count,
null);

if (device_count == 0) return ContextError.NoDevice;
if (device_count == 0) return error.NoDevice;

const devices = try self.logger.allocator.alloc (vk.PhysicalDevice,
device_count);
Expand All @@ -689,7 +680,7 @@ pub const Context = struct
}

if (max_score == 0 or self.physical_device == null)
return ContextError.NoSuitableDevice;
return error.NoSuitableDevice;

try self.logger.app (.DEBUG, "pick a {d}/{d} Vulkan physical device OK",
.{ max_score, MAX_DEVICE_SCORE, });
Expand Down Expand Up @@ -956,7 +947,7 @@ pub const Context = struct
}
}

return ContextError.NoSuitableMemoryType;
return error.NoSuitableMemoryType;
}

fn init_offscreen (self: *@This ()) !void
Expand Down Expand Up @@ -2128,7 +2119,7 @@ pub const Context = struct
id += 1;
}

if (!available) return ContextError.NoAvailableFilename;
if (!available) return error.NoAvailableFilename;

filename = try std.fmt.allocPrint (allocator, "{s}.ppm", .{ filename, });
return filename;
Expand Down
10 changes: 2 additions & 8 deletions src/vk/instance/default.zig
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ pub const instance_vk = struct
break :blk &optionals;
};

const InitVkError = error
{
ExtensionNotSupported,
LayerNotAvailable,
};

fn debug_callback (
message_severity: vk.EXT.DebugUtils.Message.Severity.Flags,
message_type: vk.EXT.DebugUtils.Message.Type.Flags,
Expand Down Expand Up @@ -114,7 +108,7 @@ pub const instance_vk = struct
} else {
try self.logger.app (.ERROR, "{s} required layer is not available",
.{ layer });
return InitVkError.LayerNotAvailable;
return error.LayerNotAvailable;
}

flag = false;
Expand Down Expand Up @@ -224,7 +218,7 @@ pub const instance_vk = struct
{
try self.logger.app (.ERROR,
"{s} required extension is not supported", .{ required_ext });
return InitVkError.ExtensionNotSupported;
return error.ExtensionNotSupported;
}
}

Expand Down

0 comments on commit 6eda750

Please sign in to comment.