agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Jim Nasby <[email protected]>
To: Pg Hackers <[email protected]>
Subject: Improved error reporting in format()
Date: Sat, 2 Jan 2016 17:57:48 -0600
Message-ID: <[email protected]> (raw)
List-Unsubscribe: <mailto:[email protected]?body=unsub%20pgsql-hackers>
The current error message for an invalid format conversion type is
extremely confusing except in the simplest of uses:
select format( '% moo');
ERROR: unrecognized conversion type specifier " "
Obviously in that example you can figure out what's going on, but
frequently format() is used in a complex context where it's not at all
obvious that format is the problem. Even worse, "conversion" makes it
sound like a localization issue.
Attached patch clarifies that %-related error messages with hints as
well as (IMHO) improving the clarity of the message:
select format( '% moo');
ERROR: unrecognized format() type specifier " "
HINT: For a single "%" use "%%"
I also made the use of "format()" consistent in all the other error
messages.
--
Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX
Experts in Analytics, Data Architecture and PostgreSQL
Data in Trouble? Get it in Treble! http://BlueTreble.com
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index a89f586..a4552ad 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -4647,7 +4647,8 @@ text_reverse(PG_FUNCTION_ARGS)
if (++(ptr) >= (end_ptr)) \
ereport(ERROR, \
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
- errmsg("unterminated format specifier"))); \
+ errmsg("unterminated format() type specifier"), \
+ errhint("For a single \"%%\" use \"%%%%\"."))); \
} while (0)
/*
@@ -4779,8 +4780,9 @@ text_format(PG_FUNCTION_ARGS)
if (strchr("sIL", *cp) == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized conversion type specifier \"%c\"",
- *cp)));
+ errmsg("unrecognized format() type specifier \"%c\"",
+ *cp),
+ errhint("For a single \"%%\" use \"%%%%\".")));
/* If indirect width was specified, get its value */
if (widthpos >= 0)
@@ -4791,7 +4793,7 @@ text_format(PG_FUNCTION_ARGS)
if (arg >= nargs)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("too few arguments for format")));
+ errmsg("too few arguments for format()")));
/* Get the value and type of the selected argument */
if (!funcvariadic)
@@ -4899,8 +4901,9 @@ text_format(PG_FUNCTION_ARGS)
/* should not get here, because of previous check */
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized conversion type specifier \"%c\"",
- *cp)));
+ errmsg("unrecognized format() type specifier \"%c\"",
+ *cp),
+ errhint("For a single \"%%\" use \"%%%%\".")));
break;
}
}
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments:
[text/plain] patch.diff (1.7K, ../[email protected]/2-patch.diff)
download | inline diff:
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index a89f586..a4552ad 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -4647,7 +4647,8 @@ text_reverse(PG_FUNCTION_ARGS)
if (++(ptr) >= (end_ptr)) \
ereport(ERROR, \
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), \
- errmsg("unterminated format specifier"))); \
+ errmsg("unterminated format() type specifier"), \
+ errhint("For a single \"%%\" use \"%%%%\"."))); \
} while (0)
/*
@@ -4779,8 +4780,9 @@ text_format(PG_FUNCTION_ARGS)
if (strchr("sIL", *cp) == NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized conversion type specifier \"%c\"",
- *cp)));
+ errmsg("unrecognized format() type specifier \"%c\"",
+ *cp),
+ errhint("For a single \"%%\" use \"%%%%\".")));
/* If indirect width was specified, get its value */
if (widthpos >= 0)
@@ -4791,7 +4793,7 @@ text_format(PG_FUNCTION_ARGS)
if (arg >= nargs)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("too few arguments for format")));
+ errmsg("too few arguments for format()")));
/* Get the value and type of the selected argument */
if (!funcvariadic)
@@ -4899,8 +4901,9 @@ text_format(PG_FUNCTION_ARGS)
/* should not get here, because of previous check */
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("unrecognized conversion type specifier \"%c\"",
- *cp)));
+ errmsg("unrecognized format() type specifier \"%c\"",
+ *cp),
+ errhint("For a single \"%%\" use \"%%%%\".")));
break;
}
}
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: Improved error reporting in format()
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox