Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ef99bd

Browse files
committed
Improve some JSON error messages.
These messages are new in 9.4, which hasn't been released yet, soback-patch to REL9_4_STABLE.Daniele Varrazzo
1 parentee646df commit0ef99bd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

‎src/backend/utils/adt/json.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,7 @@ json_object_agg_transfn(PG_FUNCTION_ARGS)
19101910
if (val_type==InvalidOid||val_type==UNKNOWNOID)
19111911
ereport(ERROR,
19121912
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1913-
errmsg("arg 1:could not determine data type")));
1913+
errmsg("could not determine data type for argument %d",1)));
19141914

19151915
add_json(arg, false,state,val_type, true);
19161916

@@ -1934,7 +1934,7 @@ json_object_agg_transfn(PG_FUNCTION_ARGS)
19341934
if (val_type==InvalidOid||val_type==UNKNOWNOID)
19351935
ereport(ERROR,
19361936
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1937-
errmsg("arg 2:could not determine data type")));
1937+
errmsg("could not determine data type for argument %d",2)));
19381938

19391939
add_json(arg,PG_ARGISNULL(2),state,val_type, false);
19401940

@@ -1980,7 +1980,8 @@ json_build_object(PG_FUNCTION_ARGS)
19801980
if (nargs %2!=0)
19811981
ereport(ERROR,
19821982
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1983-
errmsg("invalid number or arguments: object must be matched key value pairs")));
1983+
errmsg("invalid number or arguments"),
1984+
errhint("Object must be matched key value pairs.")));
19841985

19851986
result=makeStringInfo();
19861987

@@ -1994,7 +1995,8 @@ json_build_object(PG_FUNCTION_ARGS)
19941995
if (PG_ARGISNULL(i))
19951996
ereport(ERROR,
19961997
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1997-
errmsg("arg %d: key cannot be null",i+1)));
1998+
errmsg("argument %d cannot be null",i+1),
1999+
errhint("Object keys should be text.")));
19982000
val_type=get_fn_expr_argtype(fcinfo->flinfo,i);
19992001

20002002
/*
@@ -2016,7 +2018,8 @@ json_build_object(PG_FUNCTION_ARGS)
20162018
if (val_type==InvalidOid||val_type==UNKNOWNOID)
20172019
ereport(ERROR,
20182020
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2019-
errmsg("arg %d: could not determine data type",i+1)));
2021+
errmsg("could not determine data type for argument %d",
2022+
i+1)));
20202023
appendStringInfoString(result,sep);
20212024
sep=", ";
20222025
add_json(arg, false,result,val_type, true);
@@ -2042,7 +2045,8 @@ json_build_object(PG_FUNCTION_ARGS)
20422045
if (val_type==InvalidOid||val_type==UNKNOWNOID)
20432046
ereport(ERROR,
20442047
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2045-
errmsg("arg %d: could not determine data type",i+2)));
2048+
errmsg("could not determine data type for argument %d",
2049+
i+2)));
20462050
add_json(arg,PG_ARGISNULL(i+1),result,val_type, false);
20472051

20482052
}
@@ -2099,7 +2103,8 @@ json_build_array(PG_FUNCTION_ARGS)
20992103
if (val_type==InvalidOid||val_type==UNKNOWNOID)
21002104
ereport(ERROR,
21012105
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2102-
errmsg("arg %d: could not determine data type",i+1)));
2106+
errmsg("could not determine data type for argument %d",
2107+
i+1)));
21032108
appendStringInfoString(result,sep);
21042109
sep=", ";
21052110
add_json(arg,PG_ARGISNULL(i),result,val_type, false);

‎src/test/regress/expected/json.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,8 @@ SELECT json_build_object(1,2);
11501150

11511151
-- keys must be scalar and not null
11521152
SELECT json_build_object(null,2);
1153-
ERROR: arg 1: key cannot be null
1153+
ERROR: argument 1 cannot be null
1154+
HINT: Object keys should be text.
11541155
SELECT json_build_object(r,2) FROM (SELECT 1 AS a, 2 AS b) r;
11551156
ERROR: key value must be scalar, not array, composite, or json
11561157
SELECT json_build_object(json '{"a":1,"b":2}', 3);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp