Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail on SQL format errors #227

Merged
merged 1 commit into from
Nov 13, 2024
Merged

Conversation

pgiraud
Copy link
Member

@pgiraud pgiraud commented Nov 13, 2024

For example, with the following query the SQL formatter / highlighter raises an error:

SELECT id AS srvid,
                CASE WHEN id = $1 THEN
                   $2
                ELSE
                   COALESCE(alias, hostname || $3 || port)
                END AS alias,
                CASE WHEN id = $4 THEN $5 ELSE hostname END as hostname,
                CASE WHEN id = $6 THEN $7 ELSE port END AS port,
                CASE WHEN id = $8 THEN set.setting
                    ELSE s.version::text
                END AS version
                FROM public.powa_servers s
                LEFT JOIN pg_settings set ON set.name = $9
                    AND s.id = $10

Until this can be fixed in the library and in order to prevent PoWA to work improperly (navigation broken), we catch the error and show the unhighlighted value.

Copy link
Member

@rjuju rjuju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

out of curiosity, what is the error raised by the mentioned query?

@pgiraud
Copy link
Member Author

pgiraud commented Nov 13, 2024

With the above query the error is

Unexpected RESERVED_CLAUSE token: {"type":"RESERVED_CLAUSE","raw":"set","text":"SET","start":368,"precedingWhitespace":" "}. Instead, I was expecting to see one of the following:
[...]

But I've seen other errors (like Unexpected OPERATOR token: {"type":"OPERATOR","raw":"=","text":"=","start":77}).

I'll dig this a bit more with small example queries directly against the library. It may have already been fixed.

@pgiraud pgiraud merged commit 3d06179 into master Nov 13, 2024
1 check passed
@pgiraud pgiraud deleted the catch_sql_formatter_errors branch November 13, 2024 16:02
@pgiraud
Copy link
Member Author

pgiraud commented Nov 14, 2024

For the record, the formatter doesn't like the set alias for the pg_settings table in the SQL. I reported an issue on the sql-formatter project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants