From 34ff7e827b22595ddd2fa1ea3585db07045f99bf Mon Sep 17 00:00:00 2001 From: utox39 Date: Fri, 9 May 2025 11:52:22 +0200 Subject: [PATCH] refactor(macos): handle the EnvironmentVariableNotFound error for the env vars 'LANG' and 'TERM_PROGRAM' --- src/macos/system.zig | 4 +++- src/macos/user.zig | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/macos/system.zig b/src/macos/system.zig index f7c8857..980e8fa 100644 --- a/src/macos/system.zig +++ b/src/macos/system.zig @@ -33,7 +33,9 @@ pub fn getHostname(allocator: std.mem.Allocator) ![]u8 { } pub fn getLocale(allocator: std.mem.Allocator) ![]u8 { - const locale = try std.process.getEnvVarOwned(allocator, "LANG"); + const locale = std.process.getEnvVarOwned(allocator, "LANG") catch |err| if (err == error.EnvironmentVariableNotFound) { + return allocator.dupe(u8, "Unknown"); + } else return err; return locale; } diff --git a/src/macos/user.zig b/src/macos/user.zig index 82a8372..34abd0f 100644 --- a/src/macos/user.zig +++ b/src/macos/user.zig @@ -27,6 +27,8 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 { } pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 { - const term_progrm = try std.process.getEnvVarOwned(allocator, "TERM_PROGRAM"); + const term_progrm = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) { + return allocator.dupe(u8, "Unknown"); + } else return err; return term_progrm; }