teamhackback / hb-ddb

Vibe.d Async native D Postgres client
https://teamhackback.github.io/hb-ddb/docs/ddb/pg.html
1 stars 1 forks source link

Handle parse errors #10

Open wilzbach opened 7 years ago

wilzbach commented 7 years ago

         void sendParseMessage(string statementName, string query, int[] oids)
         {
             int len = cast(int)(4 + statementName.length + 1 + query.length + 1 + 2 + oids.length * 4);                   
-       +           bool failed;
-            stream.write('P');     +            try stream.write('P');
+           catch (Exception e) {
+               failed = true;
+           }
+           if (failed) {
+               close();
+               throw new Exception("Error in parse: " ~ statementName ~ " query: " ~ query);
+           }
wilzbach commented 7 years ago

Errors from prepare:

        string* pos = 'P' in error.fields;
        if (pos && (*pos).to!size_t < query.length) {
            size_t idx = (*pos).to!size_t;
            size_t start;
            if (idx > 10)
                start = idx - 10;
            else start = 0;
            size_t end = min(query.length, idx + 20);
            details ~= "\n'" ~ query[start .. end].replace("\t", " ").replace("\n", " ").to!string ~ "'\n          ^";
        }
        super("Could not execute query '" ~ query ~ "' => " ~ details, fn, ln);