On Fri, Jul 12, 2024 at 10:41:14PM +0200, Daniel Gustafsson wrote:
> Mapping this case to ERRCODE_NAME_TOO_LONG seems like a legit improvement, 
> even
> though the error is likely to be quite rare in production.

Hmm.  This is interesting, still it could be confusing as
ERRCODE_NAME_TOO_LONG is used only for names, when they are longer
than NAMEDATALEN, so in context that's a bit different than a longer
file name.

How about using a new error code in class 58, say a
ERRCODE_FILE_NAME_TOO_LONG like in the attached?
ERRCODE_DUPLICATE_FILE is like that; it exists just for the mapping
with EEXIST.
--
Michael
diff --git a/src/backend/utils/errcodes.txt b/src/backend/utils/errcodes.txt
index 3250d539e1..b43a24d4bc 100644
--- a/src/backend/utils/errcodes.txt
+++ b/src/backend/utils/errcodes.txt
@@ -439,6 +439,7 @@ Section: Class 58 - System Error (errors external to PostgreSQL itself)
 58030    E    ERRCODE_IO_ERROR                                               io_error
 58P01    E    ERRCODE_UNDEFINED_FILE                                         undefined_file
 58P02    E    ERRCODE_DUPLICATE_FILE                                         duplicate_file
+58P03    E    ERRCODE_FILE_NAME_TOO_LONG                                     file_name_too_long
 
 Section: Class F0 - Configuration File Error
 
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 3e42f5754f..479e312ba7 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -929,6 +929,10 @@ errcode_for_file_access(void)
 			edata->sqlerrcode = ERRCODE_IO_ERROR;
 			break;
 
+		case ENAMETOOLONG:		/* File name too long */
+			edata->sqlerrcode = ERRCODE_FILE_NAME_TOO_LONG;
+			break;
+
 			/* All else is classified as internal errors */
 		default:
 			edata->sqlerrcode = ERRCODE_INTERNAL_ERROR;

Attachment: signature.asc
Description: PGP signature

Reply via email to