if (enc == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized encoding: \"%s\"", namebuf)));
+ errmsg("unrecognized encoding: \"%s\"", namebuf),
+ errhint("Valid encodings are \"%s\", \"%s\", \"%s\", and \"%s\".",
+ "base64", "base64url", "escape", "hex")));
dataptr = VARDATA_ANY(data);
datalen = VARSIZE_ANY_EXHDR(data);
if (enc == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized encoding: \"%s\"", namebuf)));
+ errmsg("unrecognized encoding: \"%s\"", namebuf),
+ errhint("Valid encodings are \"%s\", \"%s\", \"%s\", and \"%s\".",
+ "base64", "base64url", "escape", "hex")));
dataptr = VARDATA_ANY(data);
datalen = VARSIZE_ANY_EXHDR(data);
\x1234567890abcdef00
(1 row)
+-- report an error with a hint listing valid encodings when an invalid encoding is specified
+SELECT encode('\x01'::bytea, 'invalid'); -- error
+ERROR: unrecognized encoding: "invalid"
+HINT: Valid encodings are "base64", "base64url", "escape", and "hex".
+SELECT decode('00', 'invalid'); -- error
+ERROR: unrecognized encoding: "invalid"
+HINT: Valid encodings are "base64", "base64url", "escape", and "hex".
--
-- base64url encoding/decoding
--
SELECT encode('\x1234567890abcdef00', 'escape');
SELECT decode(encode('\x1234567890abcdef00', 'escape'), 'escape');
+-- report an error with a hint listing valid encodings when an invalid encoding is specified
+SELECT encode('\x01'::bytea, 'invalid'); -- error
+SELECT decode('00', 'invalid'); -- error
+
--
-- base64url encoding/decoding
--