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

Best-effort mode even if there is an error #59

Open
mrflip opened this issue Nov 22, 2022 · 0 comments
Open

Best-effort mode even if there is an error #59

mrflip opened this issue Nov 22, 2022 · 0 comments

Comments

@mrflip
Copy link

mrflip commented Nov 22, 2022

I am using the prettier plugin programmatically to reformat the queries we send for logging/debugging purposes, and so probably the most important queries we'd like to prettify are the ones that won't perfectly parse.

Is there any straightforward way to have a 'best-effort' mode that will do what it can even if the parser can't proceed past a certain point?

Compare debugging this:

error: DB problem 'syntax error at or near "on"' sending query:    
    insert into "ndd" ("crTC", "handle", "id", "idkey", "image0ID", "locID", "note0", "okey", "productID", "purchaseID", "purchasingID", "quantity", "srcID", "steptag", "title", "tkvTC", "typename", "upTC", "vendorID", "viz") select 'val_1'::varchar AS "crTC", 'val_2'::varchar AS "handle", 'val_3'::varchar AS "id", 'val_4'::varchar AS "idkey", 'val_5'::varchar AS "image0ID", 'val_6'::varchar AS "locID", 'val_7'::varchar AS "note0", 'val_8'::varchar AS "okey", 'val_9'::varchar AS "productID", 'val_10'::varchar AS "purchaseID", 'val_11'::varchar AS "purchasingID", 12::integer AS "quantity", 'val_13'::varchar AS "srcID", 'val_14' AS "steptag", 'val_15'::varchar AS "title", 'val_16'::varchar AS "tkvTC", 'val_17'::varchar AS "typename", 'val_18'::varchar AS "upTC", 'val_19'::varchar AS "vendorID", 'val_20' AS "viz" on conflict do nothing on conflict ("true") do update set "image0ID" = 'val_21',"note0" = 'val_22',"quantity" = 'val_23',"steptag" = 'val_24',"title" = 'val_25',"viz" = 'val_26' returning "crTC", "handle", "id", "idkey", "image0ID", "locID", "note0", "okey", "productID", "purchaseID", "purchasingID", "quantity", "srcID", "steptag", "title", "tkvTC", "typename", "upTC", "vendorID", "viz" "handle", "id", "idkey", "image0ID", "locID", "note0", "okey", "productID", "purchaseID", "purchasingID", "quantity", "srcID", "steptag", "title", "tkvTC", "typename", "upTC", "vendorID", "viz") select var_1::varchar AS "crTC", var_2::varchar AS "handle", var_3::varchar AS "id", var_4::varchar AS "idkey", var_5::varchar AS "image0ID", var_6::varchar AS "locID", var_7::varchar AS "note0", var_8::varchar AS "okey", var_9::varchar AS "productID", var_10::varchar AS "purchaseID", var_11::varchar AS "purchasingID", var_12::integer AS "quantity", var_13::varchar AS "srcID", var_14 AS "steptag", var_15::varchar AS "title", var_16::varchar AS "tkvTC", var_17::varchar AS "typename", var_18::varchar AS "upTC", var_19::varchar AS "vendorID", var_20 AS "viz" on conflict do nothing on conflict ("true") do update set "image0ID" = var_21,"note0" = var_22,"quantity" = var_23,"steptag" = var_24,"title" = var_25,"viz" = var_26 returning "crTC", "handle", "id", "idkey", "image0ID", "locID", "note0", "okey", "productID", "purchaseID", "purchasingID", "quantity", "srcID", "steptag", "title", "tkvTC", "typename", "upTC", "vendorID", "viz"

to debugging this:

DB problem 'syntax error at or near "on"' sending query:
  INSERT INTO "ndd" (
    "crTC", "handle", "id", "idkey", "image0ID", "locID", "note0", "okey", "productID", "purchaseID", "purchasingID", "quantity", "srcID", "steptag", "title", "tkvTC", "typename", "upTC", "vendorID", "viz"
  )
  select 'val_1'::varchar AS "crTC",
     'val_2'::varchar AS "handle",
     'val_3'::varchar AS "id",
     'val_4'::varchar AS "idkey",
     'val_5'::varchar AS "image0ID",
     'val_6'::varchar AS "locID",
     'val_7'::varchar AS "note0",
     'val_8'::varchar AS "okey",
     'val_9'::varchar AS "productID",
     'val_10'::varchar AS "purchaseID",
     'val_11'::varchar AS "purchasingID",
     12::integer AS "quantity",
     'val_13'::varchar AS "srcID",
     'val_14' AS "steptag",
     'val_15'::varchar AS "title",
     'val_16'::varchar AS "tkvTC",
     'val_17'::varchar AS "typename",
     'val_18'::varchar AS "upTC",
     'val_19'::varchar AS "vendorID",
     'val_20' AS "viz"
  on 
-- ^^^ Parser cannot proceed: Unexpected token at 1:842
conflict do nothing on conflict ("true") do update set "image0ID" = var_21,"note0" = var_22,"quantity" = var_23,"steptag" = var_24,"title" = var_25,"viz" = var_26 returning "crTC", "handle", "id", "idkey", "image0ID", "locID", "note0", "okey", "productID", "purchaseID", "purchasingID", "quantity", "srcID", "steptag", "title", "tkvTC", "typename", "upTC", "vendorID", "viz"

If that's too aspirational, is there a way to have the plugin snip out the context around where it failed? The plugin error as it stands is Unexpected token at 1:842, but this would be much more pleasant:

Unexpected token at 1:842, near this segment:
        al_20' AS "viz" on conflict do nothing on conflict ("true") do update set "image
                                              ^^^
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

No branches or pull requests

1 participant