Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ fn run(alloc: Allocator) !void {
const server = &_server.?;
defer server.deinit();

server.run(address, opts.timeout * 1000) catch |err| {
// max timeout of 1 week.
const timeout = if (opts.timeout > 604_800) 604_800_000 else @as(i32, @intCast(opts.timeout)) * 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should to either:

  • add in the help the indication we take a max of 1 week timeout
  • error the command if the value is bigger than 1 week.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't @as(i32, opts.timeout) enough? why do we need @intCast?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expanded on the --help text. I removed the @intcast

server.run(address, timeout) catch |err| {
log.fatal(.app, "server run error", .{ .err = err });
return err;
};
Expand Down Expand Up @@ -268,7 +270,7 @@ const Command = struct {
const Serve = struct {
host: []const u8,
port: u16,
timeout: u16,
timeout: u31,
common: Common,
};

Expand Down Expand Up @@ -465,7 +467,7 @@ fn parseServeArgs(
) !Command.Serve {
var host: []const u8 = "127.0.0.1";
var port: u16 = 9222;
var timeout: u16 = 10;
var timeout: u31 = 10;
var common: Command.Common = .{};

while (args.next()) |opt| {
Expand Down Expand Up @@ -497,7 +499,7 @@ fn parseServeArgs(
return error.InvalidArgument;
};

timeout = std.fmt.parseInt(u16, str, 10) catch |err| {
timeout = std.fmt.parseInt(u31, str, 10) catch |err| {
log.fatal(.app, "invalid argument value", .{ .arg = "--timeout", .err = err });
return error.InvalidArgument;
};
Expand Down