[PATCH] Improve bytea error messages
Hi all
After someone reported somewhat less than informative errors in bytea
decoding (http://stackoverflow.com/q/24588866/398670) I thought I'd put
together a quick patch to improve the errors here.
Please merge.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Attachments:
0001-Improve-bytea-decoding-error-messages.patchtext/x-patch; name=0001-Improve-bytea-decoding-error-messages.patchDownload
>From 1f8b96526ca19a8843960b6a6ec08357b1f166a8 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Sun, 6 Jul 2014 16:15:21 +0800
Subject: [PATCH] Improve bytea decoding error messages
---
src/backend/utils/adt/encode.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c
index 46993ba..67fb574 100644
--- a/src/backend/utils/adt/encode.c
+++ b/src/backend/utils/adt/encode.c
@@ -292,7 +292,7 @@ b64_decode(const char *src, unsigned len, char *dst)
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unexpected \"=\"")));
+ errmsg("unexpected \"=\" while decoding base64 sequence")));
}
b = 0;
}
@@ -304,7 +304,7 @@ b64_decode(const char *src, unsigned len, char *dst)
if (b < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid symbol")));
+ errmsg("invalid symbol '%c' while decoding base64 sequence", (int) c)));
}
/* add it to buffer */
buf = (buf << 6) + b;
@@ -324,7 +324,7 @@ b64_decode(const char *src, unsigned len, char *dst)
if (pos != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid end sequence")));
+ errmsg("invalid base64 end sequence (missing padding or corrupt or truncated data)")));
return p - dst;
}
--
1.9.0
On Sun, Jul 6, 2014 at 4:17 AM, Craig Ringer <craig@2ndquadrant.com> wrote:
After someone reported somewhat less than informative errors in bytea
decoding (http://stackoverflow.com/q/24588866/398670) I thought I'd put
together a quick patch to improve the errors here.
The first two changes seem fine from here, but I think the use of
parentheses in the third one likely violates our message style
guidelines.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 07/08/2014 07:44 AM, Robert Haas wrote:
On Sun, Jul 6, 2014 at 4:17 AM, Craig Ringer <craig@2ndquadrant.com> wrote:
After someone reported somewhat less than informative errors in bytea
decoding (http://stackoverflow.com/q/24588866/398670) I thought I'd put
together a quick patch to improve the errors here.The first two changes seem fine from here, but I think the use of
parentheses in the third one likely violates our message style
guidelines.
Good point.
Better?
Putting it in ERRHINT is more appropriate.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
Attachments:
0001-Improve-bytea-decoding-error-messages.patchtext/x-patch; name=0001-Improve-bytea-decoding-error-messages.patchDownload
>From 285720d1b028da4fd3a1fc4b5deb006ab7b71959 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Sun, 6 Jul 2014 16:15:21 +0800
Subject: [PATCH] Improve bytea decoding error messages
---
src/backend/utils/adt/encode.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c
index 46993ba..f09e506 100644
--- a/src/backend/utils/adt/encode.c
+++ b/src/backend/utils/adt/encode.c
@@ -292,7 +292,7 @@ b64_decode(const char *src, unsigned len, char *dst)
else
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unexpected \"=\"")));
+ errmsg("unexpected \"=\" while decoding base64 sequence")));
}
b = 0;
}
@@ -304,7 +304,7 @@ b64_decode(const char *src, unsigned len, char *dst)
if (b < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid symbol")));
+ errmsg("invalid symbol '%c' while decoding base64 sequence", (int) c)));
}
/* add it to buffer */
buf = (buf << 6) + b;
@@ -324,7 +324,8 @@ b64_decode(const char *src, unsigned len, char *dst)
if (pos != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("invalid end sequence")));
+ errmsg("invalid base64 end sequence"),
+ errhint("input data is missing padding, truncated or otherwise corrupted")));
return p - dst;
}
--
1.9.0
On Tue, Jul 8, 2014 at 12:49 AM, Craig Ringer <craig@2ndquadrant.com> wrote:
On 07/08/2014 07:44 AM, Robert Haas wrote:
On Sun, Jul 6, 2014 at 4:17 AM, Craig Ringer <craig@2ndquadrant.com> wrote:
After someone reported somewhat less than informative errors in bytea
decoding (http://stackoverflow.com/q/24588866/398670) I thought I'd put
together a quick patch to improve the errors here.The first two changes seem fine from here, but I think the use of
parentheses in the third one likely violates our message style
guidelines.Good point.
Better?
Putting it in ERRHINT is more appropriate.
Looks OK to me. Committed.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers