static void report_parse_error()

in src/backend/utils/adt/agtype_parser.c [1153:1253]


static void report_parse_error(agtype_parse_context ctx,
                               agtype_lex_context *lex)
{
    char *token;
    int toklen;

    /* Handle case where the input ended prematurely. */
    if (lex->token_start == NULL || lex->token_type == AGTYPE_TOKEN_END)
    {
        ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                        errmsg("invalid input syntax for type %s", "agtype"),
                        errdetail("The input string ended unexpectedly."),
                        report_agtype_context(lex)));
    }

    /* Separate out the current token. */
    toklen = lex->token_terminator - lex->token_start;
    token = palloc(toklen + 1);
    memcpy(token, lex->token_start, toklen);
    token[toklen] = '\0';

    /* Complain, with the appropriate detail message. */
    if (ctx == AGTYPE_PARSE_END)
    {
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for type %s", "agtype"),
                 errdetail("Expected end of input, but found \"%s\".", token),
                 report_agtype_context(lex)));
    }
    else
    {
        switch (ctx)
        {
        case AGTYPE_PARSE_VALUE:
            ereport(
                ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for type %s", "agtype"),
                 errdetail("Expected agtype value, but found \"%s\".", token),
                 report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_STRING:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail("Expected string, but found \"%s\".", token),
                     report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_ARRAY_START:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail(
                         "Expected array element or \"]\", but found \"%s\".",
                         token),
                     report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_ARRAY_NEXT:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail("Expected \",\" or \"]\", but found \"%s\".",
                               token),
                     report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_OBJECT_START:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail("Expected string or \"}\", but found \"%s\".",
                               token),
                     report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_OBJECT_LABEL:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail("Expected \":\", but found \"%s\".", token),
                     report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_OBJECT_NEXT:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail("Expected \",\" or \"}\", but found \"%s\".",
                               token),
                     report_agtype_context(lex)));
            break;
        case AGTYPE_PARSE_OBJECT_COMMA:
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                     errmsg("invalid input syntax for type %s", "agtype"),
                     errdetail("Expected string, but found \"%s\".", token),
                     report_agtype_context(lex)));
            break;
        default:
            elog(ERROR, "unexpected agtype parse state: %d", ctx);
        }
    }
}