Fix for no internet and no local versions installed
This commit is contained in:
		
							parent
							
								
									6ea3710e4f
								
							
						
					
					
						commit
						ecb19ad647
					
				
							
								
								
									
										16
									
								
								src/zim.zig
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/zim.zig
									
									
									
									
									
								
							@ -156,9 +156,13 @@ fn getRemoteVersionsSlice(allocator: std.mem.Allocator) ZimError![]const ZigVers
 | 
			
		||||
        var client = std.http.Client{ .allocator = allocator };
 | 
			
		||||
        defer client.deinit();
 | 
			
		||||
 | 
			
		||||
        var request = client.request(.GET, versions_json_uri, headers, .{}) catch {
 | 
			
		||||
            std.debug.print("Error creating request\n", .{});
 | 
			
		||||
        var request = client.request(.GET, versions_json_uri, headers, .{}) catch |err| {
 | 
			
		||||
            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;
 | 
			
		||||
            }
 | 
			
		||||
            std.debug.print("Error creating request\n{any}\n", .{err});
 | 
			
		||||
            return ZimError.Unexpected;
 | 
			
		||||
        };
 | 
			
		||||
        defer request.deinit();
 | 
			
		||||
 | 
			
		||||
@ -239,7 +243,7 @@ fn shellName(s: ?ShellType) string {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn printZimPathHelp(shell_tag: ?ShellType, zim_path: string) void {
 | 
			
		||||
    if (shell_tag == undefined) {
 | 
			
		||||
    if (shell_tag == null) {
 | 
			
		||||
        std.debug.print("Unrecognized shell\n", .{});
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
@ -311,7 +315,7 @@ fn downloadAndExtractTarball(allocator: std.mem.Allocator, zv: ZigVersion) ZimEr
 | 
			
		||||
    const tar_buf_len = 38;
 | 
			
		||||
    var tar_arr: [tar_buf_len]u8 = undefined;
 | 
			
		||||
    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;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -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 });
 | 
			
		||||
                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(
 | 
			
		||||
                    \\
 | 
			
		||||
@ -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.
 | 
			
		||||
                    \\
 | 
			
		||||
                , .{});
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return;
 | 
			
		||||
        },
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user