Making error message more user-friendly with spaces in a URI
Hi,
I made a patch to make the error message more user-friendly when using a
URI to connect a database with psql.
Current Error Message:
$ psql "postgres://localhost:5432/postgres?application_name=a b"
psql: error: trailing data found: "a b"
Currently, if spaces exist in the URI, psql displays this generic error
message.
New Error Message (with patch):
psql: error: found unexpected spaces: “a b“. Did you forget to
percent-encode spaces?
This revised message is clearer and more concise, guiding users to check
for encoding issues.
Regards,
Yushi Ogiwara
Attachments:
user_friendly_error.difftext/x-diff; name=user_friendly_error.diffDownload
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 61c025ff3b..957b565f77 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -6839,7 +6839,7 @@ end:
/* Not at the end of the string yet? Fail. */
if (*q != '\0')
{
- libpq_append_error(errorMessage, "trailing data found: \"%s\"", str);
+ libpq_append_error(errorMessage, "found unexpected spaces: \"%s\". Did you forget to percent-encode spaces?", str);
free(buf);
return NULL;
}
I made a patch to make the error message more user-friendly when using a
URI to connect a database with psql.
Hi, Yushi! I could not find this line in the master branch and I couldn't
apply this patch. I only see this error in the test (I think the test
should also be changed), but the idea of fixing the error looks good to me.
Best Regards, Stepan Neretin!
On Thu, Oct 31, 2024 at 10:35:41PM +0700, Stepan Neretin wrote:
Hi, Yushi! I could not find this line in the master branch and I couldn't
apply this patch. I only see this error in the test (I think the test
should also be changed), but the idea of fixing the error looks good to me.
This line exists on HEAD and the patch applies cleanly today as of
2d8bff603c9e. So perhaps just make sure that you are up to date?
--
Michael
$ psql "postgres://localhost:5432/postgres?application_name=a b"
psql: error: trailing data found: "a b"
This works fine for me, and sets a space in the application_name string as
expected. Do you have a different example?
Cheers,
Greg
On 2024/11/01 22:38, Greg Sabino Mullane wrote:
$ psql "postgres://localhost:5432/postgres?application_name=a b"
psql: error: trailing data found: "a b"This works fine for me, and sets a space in the application_name string as expected. Do you have a different example?
You'll encounter the error message if you run the example command against HEAD.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
On 2024/10/31 10:22, Yushi Ogiwara wrote:
Hi,
I made a patch to make the error message more user-friendly when using a URI to connect a database with psql.
Current Error Message:
$ psql "postgres://localhost:5432/postgres?application_name=a b"
psql: error: trailing data found: "a b"Currently, if spaces exist in the URI, psql displays this generic error message.
New Error Message (with patch):
psql: error: found unexpected spaces: “a b“. Did you forget to percent-encode spaces?
This revised message is clearer and more concise, guiding users to check for encoding issues.
I agree the error message could be improved.
The phrasing "Did you forget" feels a bit indirect to me.
How about using something clearer and more direct instead?
-----------
psql: error: unexpected spaces found "a b", use percent-encoded spaces instead
-----------
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
On Wed, Nov 6, 2024 at 01:09:12AM +0900, Fujii Masao wrote:
On 2024/10/31 10:22, Yushi Ogiwara wrote:
Hi,
I made a patch to make the error message more user-friendly when using a URI to connect a database with psql.
Current Error Message:
$ psql "postgres://localhost:5432/postgres?application_name=a b"
psql: error: trailing data found: "a b"Currently, if spaces exist in the URI, psql displays this generic error message.
New Error Message (with patch):
psql: error: found unexpected spaces: “a b“. Did you forget to percent-encode spaces?
This revised message is clearer and more concise, guiding users to check for encoding issues.
I agree the error message could be improved.
The phrasing "Did you forget" feels a bit indirect to me.
How about using something clearer and more direct instead?-----------
psql: error: unexpected spaces found "a b", use percent-encoded spaces instead
-----------
+1
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EDB https://enterprisedb.com
When a patient asks the doctor, "Am I going to die?", he means
"Am I going to die soon?"
On Mon, Nov 18, 2024 at 02:59:18PM -0500, Bruce Momjian wrote:
On Wed, Nov 6, 2024 at 01:09:12AM +0900, Fujii Masao wrote:
The phrasing "Did you forget" feels a bit indirect to me.
How about using something clearer and more direct instead?-----------
psql: error: unexpected spaces found "a b", use percent-encoded spaces instead
-----------+1
Could it be better to mention %20 in the error message? Say an
addition like:
"unexpected spaces found \"%s\", use percent-encoded spaces (%%20)
instead"
--
Michael
Michael Paquier <michael@paquier.xyz> writes:
Could it be better to mention %20 in the error message? Say an
addition like:
"unexpected spaces found \"%s\", use percent-encoded spaces (%%20) instead"
+1. Also the grammar seems a bit off; how about
"unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead"
regards, tom lane
On Mon, Nov 18, 2024 at 07:52:08PM -0500, Tom Lane wrote:
+1. Also the grammar seems a bit off; how about
"unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead"
That's better, thanks. This one's on me, so I think that I'll just go
fix that today with this wording. This patch was on my bucket list,
just lost sight of it.
--
Michael