Fix for no internet and no local versions installed
This commit is contained in:
parent
6ea3710e4f
commit
ecb19ad647
44
src/zim.zig
44
src/zim.zig
|
@ -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) {
|
||||||
return ZimError.NetworkError;
|
std.debug.print("Name Server for {s} could not be resolved. Check your internet connection.", .{versions_json_url});
|
||||||
|
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,15 +315,15 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Buffer lenght for `<zim_path>/versions/<tarbll_file_name>`
|
// Buffer lenght for `<zim_path>/versions/<tarbll_file_name>`
|
||||||
const full_tar_buf_len = buf_len + tar_buf_len + 10;
|
const full_tar_buf_len = buf_len + tar_buf_len + 10;
|
||||||
var full_tar_arr: [full_tar_buf_len]u8 = undefined;
|
var full_tar_arr: [full_tar_buf_len]u8 = undefined;
|
||||||
var full_tar_buf = full_tar_arr[0..];
|
var full_tar_buf = full_tar_arr[0..];
|
||||||
const full_path_tarball_file_name = std.fmt.bufPrint(full_tar_buf, "{s}/versions/{s}", .{ zim_path, tarball_file_name}) catch {
|
const full_path_tarball_file_name = std.fmt.bufPrint(full_tar_buf, "{s}/versions/{s}", .{ zim_path, tarball_file_name }) catch {
|
||||||
return ZimError.Memory;
|
return ZimError.Memory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -347,10 +351,10 @@ fn downloadAndExtractTarball(allocator: std.mem.Allocator, zv: ZigVersion) ZimEr
|
||||||
};
|
};
|
||||||
|
|
||||||
// Remove tarball file
|
// Remove tarball file
|
||||||
zim_dir.deleteFile(full_path_tarball_file_name) catch |err| {
|
zim_dir.deleteFile(full_path_tarball_file_name) catch |err| {
|
||||||
std.debug.print("Could not remove {s}: {any}\n", .{tarball_file_name, err});
|
std.debug.print("Could not remove {s}: {any}\n", .{ tarball_file_name, err });
|
||||||
return ZimError.BadIO;
|
return ZimError.BadIO;
|
||||||
};
|
};
|
||||||
|
|
||||||
std.debug.print("{s} is installed and now locally available!\n", .{zv.version_string});
|
std.debug.print("{s} is installed and now locally available!\n", .{zv.version_string});
|
||||||
}
|
}
|
||||||
|
@ -472,13 +476,17 @@ 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;
|
||||||
}
|
}
|
||||||
std.debug.print("\n", .{});
|
if (i == 0) {
|
||||||
std.debug.print(
|
std.debug.print("\nNo local versions installed\nTry `zim install help`\n", .{});
|
||||||
\\
|
} else {
|
||||||
\\ Run `zim use` to select which version you want active in your environment.
|
std.debug.print("\n", .{});
|
||||||
\\ You can also just specify the index of the version you would like to use.
|
std.debug.print(
|
||||||
\\
|
\\
|
||||||
, .{});
|
\\ Run `zim use` to select which version you want active in your environment.
|
||||||
|
\\ You can also just specify the index of the version you would like to use.
|
||||||
|
\\
|
||||||
|
, .{});
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user