v5-0001-Improve-CREATE-EXTENSION-error-message.patch

application/octet-stream

Filename: v5-0001-Improve-CREATE-EXTENSION-error-message.patch
Type: application/octet-stream
Part: 0
Message: Re: improve CREATE EXTENSION error message

Patch

Format: format-patch
Series: patch v5-0001
Subject: Improve CREATE EXTENSION error message.
File+
src/backend/commands/extension.c 16 4
From 18194c7be0e374eed72de254cd25e8ba99f53c8b Mon Sep 17 00:00:00 2001
From: Nathan Bossart <bossartn@amazon.com>
Date: Tue, 30 Nov 2021 00:10:39 +0000
Subject: [PATCH v5 1/1] Improve CREATE EXTENSION error message.

---
 src/backend/commands/extension.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index eaa76af47b..08e5abb57d 100644
--- a/src/backend/commands/extension.c
+++ b/src/backend/commands/extension.c
@@ -487,11 +487,23 @@ parse_extension_control_file(ExtensionControlFile *control,
 
 	if ((file = AllocateFile(filename, "r")) == NULL)
 	{
-		if (version && errno == ENOENT)
+		if (errno == ENOENT)
 		{
-			/* no auxiliary file for this version */
-			pfree(filename);
-			return;
+			/* auxiliary files are optional */
+			if (version)
+			{
+				pfree(filename);
+				return;
+			}
+
+			/* missing control file indicates extension is not installed */
+			ereport(ERROR,
+					(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+					 errmsg("extension \"%s\" is not available", control->name),
+					 errdetail("Could not open extension control file \"%s\": %m.",
+							   filename),
+					 errhint("The extension must first be installed on the "
+							 "system where PostgreSQL is running.")));
 		}
 		ereport(ERROR,
 				(errcode_for_file_access(),
-- 
2.16.6