Commits

Andrew Dunstan committed e62fa09

fix error reporting

Comments (0)

Files changed (1)

src/backend/utils/adt/jsonfuncs.c

 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_object_keys on an array")));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_object_keys on a scalar")));
 }
 
 
 	if (_state->lex->lex_level == 0 && _state->search_type == JSON_SEARCH_ARRAY)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_get(int) on a non-array")));
 }
 
 	{
 		if (_state->tresult != NULL || _state->result_start != NULL)
 			ereport(ERROR,
-					(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+					(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 					 errmsg("field name is not unique in json object")));
 
 		if (_state->normalize_results &&
 
 	if (lex_level == 0 && _state->search_type == JSON_SEARCH_OBJECT)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_get(fieldname) on a non-object")));
 	else if (_state->search_type == JSON_SEARCH_PATH &&
 			 lex_level <= _state->npath)
 
 	if (_state->lex->lex_level == 0 && _state->search_type != JSON_SEARCH_PATH)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_get on a scalar")));
 	if (_state->next_scalar)
 	{
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_array_length on an object")));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_array_length on a scalar")));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_each on an array")));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_each on a scalar")));
 
 	if (_state->next_scalar)
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_unnest on an object")));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call json_unnest on a scalar")));
 }
 
 		_state->lex->token_type == JSON_TOKEN_OBJECT_START)
 	{
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 		errmsg("cannot call %s on a nested object", _state->function_name)));
 	}
 }
 	hashentry = hash_search(_state->hash, name, HASH_ENTER, &found);
 
 	if (found)
-		elog(ERROR, "duplicate key");
+		ereport(ERROR,
+				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				 errmsg("duplicate object field name: \"%s\"", fname)));
 
 	hashentry->isnull = isnull;
 	hashentry->val = _state->saved_scalar;
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 			   errmsg("cannot call %s on an array", _state->function_name)));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 			   errmsg("cannot call %s on a scalar", _state->function_name)));
 
 	_state->saved_scalar = token;
 
 	if (lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call populate_recordset on an object")));
 	else if (lex_level > 1)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 			  errmsg("cannot call populate_recordset with nested objects")));
 
 	/* set up a new hash for this entry */
 	if (_state->lex->lex_level == 1 &&
 		_state->lex->token_type != JSON_TOKEN_OBJECT_START)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 			 errmsg("must call populate_recordset on an array of objects")));
 }
 
 
 	if (_state->lex->lex_level != 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 			   errmsg("cannot call populate_recordset with nested arrays")));
 }
 
 
 	if (_state->lex->lex_level == 0)
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 				 errmsg("cannot call populate_recordset on a scalar")));
 
 	_state->saved_scalar = token;
 		_state->lex->token_type == JSON_TOKEN_OBJECT_START)
 	{
 		ereport(ERROR,
-				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
 			   errmsg("cannot call populate_recordset on a nested object")));
 	}
 }
 	hashentry = hash_search(_state->json_hash, name, HASH_ENTER, &found);
 
 	if (found)
-		elog(ERROR, "duplicate key");
+		ereport(ERROR,
+				(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+				 errmsg("duplicate object field name: \"%s\"", fname)));
 
 	hashentry->isnull = isnull;
 	hashentry->val = _state->saved_scalar;