Subject: [PATCH] Improve error reporting of getpw and getgr.

From: Taylan Kammer <[email-masked]>
Date: Tue, 18 May 2021 19:51:51 +0200

Tag: patch
Severity: minor

The attached patch fixes/improves the error-reporting of getpw and getgr.

-- 
Taylan
From 0b3faa5c01ed2d41fd7fc30e7bb4490d79ec2586 Mon Sep 17 00:00:00 2001
From: Taylan Kammer <[email-masked]>
Date: Tue, 18 May 2021 19:32:10 +0200
Subject: [PATCH] Improve error reporting of getpw and getgr.

* libguile/posix.c (scm_getpwuid): Check errno to see if a SYSERROR
should be raised; otherwise improve not-found error message.
(scm_getgrgid): Raise a meaningful error when errno isn't set.
---
 libguile/posix.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/libguile/posix.c b/libguile/posix.c
index 31c4ab192..6ce00b9b5 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -372,7 +372,12 @@ SCM_DEFINE (scm_getpwuid, "getpw", 0, 1, 0,
 		   entry = getpwnam (c_user));
     }
   if (!entry)
-    SCM_MISC_ERROR ("entry not found", SCM_EOL);
+    {
+      if (errno)
+        SCM_SYSERROR;
+      else
+        SCM_MISC_ERROR ("No such POSIX user.", scm_list_1 (user));
+    }
 
   SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (entry->pw_name));
   SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (entry->pw_passwd));
@@ -438,7 +443,12 @@ SCM_DEFINE (scm_getgrgid, "getgr", 0, 1, 0,
     STRING_SYSCALL (name, c_name,
 		    entry = getgrnam (c_name));
   if (!entry)
-    SCM_SYSERROR;
+    {
+      if (errno)
+        SCM_SYSERROR;
+      else
+        SCM_MISC_ERROR ("No such POSIX user group.", scm_list_1 (name));
+    }
 
   SCM_SIMPLE_VECTOR_SET(result, 0, scm_from_locale_string (entry->gr_name));
   SCM_SIMPLE_VECTOR_SET(result, 1, scm_from_locale_string (entry->gr_passwd));
-- 
2.30.2