Fix for no internet and no local versions installed

This commit is contained in:
Tom Cat 2023-10-23 10:54:57 -06:00
parent 6ea3710e4f
commit ecb19ad647

View File

@ -156,9 +156,13 @@ fn getRemoteVersionsSlice(allocator: std.mem.Allocator) ZimError![]const ZigVers
var client = std.http.Client{ .allocator = allocator }; var client = std.http.Client{ .allocator = allocator };
defer client.deinit(); defer client.deinit();
var request = client.request(.GET, versions_json_uri, headers, .{}) catch { var request = client.request(.GET, versions_json_uri, headers, .{}) catch |err| {
std.debug.print("Error creating request\n", .{}); if (err == error.TemporaryNameServerFailureError) {
std.debug.print("Name Server for {s} could not be resolved. Check your internet connection.", .{versions_json_url});
return ZimError.NetworkError; return ZimError.NetworkError;
}
std.debug.print("Error creating request\n{any}\n", .{err});
return ZimError.Unexpected;
}; };
defer request.deinit(); defer request.deinit();
@ -239,7 +243,7 @@ fn shellName(s: ?ShellType) string {
} }
fn printZimPathHelp(shell_tag: ?ShellType, zim_path: string) void { fn printZimPathHelp(shell_tag: ?ShellType, zim_path: string) void {
if (shell_tag == undefined) { if (shell_tag == null) {
std.debug.print("Unrecognized shell\n", .{}); std.debug.print("Unrecognized shell\n", .{});
return; return;
} }
@ -311,7 +315,7 @@ fn downloadAndExtractTarball(allocator: std.mem.Allocator, zv: ZigVersion) ZimEr
const tar_buf_len = 38; const tar_buf_len = 38;
var tar_arr: [tar_buf_len]u8 = undefined; var tar_arr: [tar_buf_len]u8 = undefined;
var tar_buf = tar_arr[0..]; var tar_buf = tar_arr[0..];
const tarball_file_name = std.fmt.bufPrint(tar_buf, "zig-{s}.tar", .{ zim_path, zv.version_string }) catch { const tarball_file_name = std.fmt.bufPrint(tar_buf, "zig-{s}.tar", .{zv.version_string}) catch {
return ZimError.Memory; return ZimError.Memory;
}; };
@ -472,6 +476,9 @@ pub fn list(allocator: std.mem.Allocator, param: string) !void {
std.debug.print("\n [{d}]\tZig Version {s}", .{ i + 1, version_str }); std.debug.print("\n [{d}]\tZig Version {s}", .{ i + 1, version_str });
i += 1; i += 1;
} }
if (i == 0) {
std.debug.print("\nNo local versions installed\nTry `zim install help`\n", .{});
} else {
std.debug.print("\n", .{}); std.debug.print("\n", .{});
std.debug.print( std.debug.print(
\\ \\
@ -479,6 +486,7 @@ pub fn list(allocator: std.mem.Allocator, param: string) !void {
\\ You can also just specify the index of the version you would like to use. \\ You can also just specify the index of the version you would like to use.
\\ \\
, .{}); , .{});
}
return; return;
}, },