diff --git a/src/libc.jl b/src/libc.jl index bbd497b..4cf7691 100644 --- a/src/libc.jl +++ b/src/libc.jl @@ -81,9 +81,13 @@ Base.show(io::IO, user::User) = print(io, "$(user.uid) ($(user.name))") ret = Libc.errno() systemerror(:getpwuid, !iszero(ret)) - ps == C_NULL && throw(ArgumentError("User $uid not found.")) - return User(ps) + if ps == C_NULL + @warn "User $uid not found." + return User("NA", uid, uid, "NA", "NA") + else + return User(ps) + end end User() = User(UInt(ccall(:geteuid, Cint, ()))) @@ -119,8 +123,12 @@ Base.show(io::IO, group::Group) = print(io, "$(group.gid) ($(group.name))") ret = Libc.errno() systemerror(:getgrgid, !iszero(ret)) - gr == C_NULL && throw(ArgumentError("Group $gid not found.")) - return Group(gr) + if gr == C_NULL + @warn "Group $gid not found." + return Group("NA", gid) + else + return Group(gr) + end end Group() = Group(UInt(ccall(:getegid, Cint, ()))) diff --git a/test/system.jl b/test/system.jl index 79c118e..e49a627 100644 --- a/test/system.jl +++ b/test/system.jl @@ -293,6 +293,18 @@ ps = PathSet(; symlink=true) @test g_int isa FilePathsBase.Group @test u_int.uid isa Unsigned @test g_int.gid isa Unsigned + + # Non-existent user or group on unix + if Sys.isunix() + u_int = FilePathsBase.User(UInt(9999)) + g_int = FilePathsBase.Group(UInt(9999)) + @test u_int isa FilePathsBase.User + @test g_int isa FilePathsBase.Group + @test u_int.uid == UInt(9999) + @test g_int.gid == UInt(9999) + @test u_int.name == "NA" + @test g_int.name == "NA" + end end end