stablekernel / postgresql-dart

Dart PostgreSQL driver: supports extended query format, binary protocol and statement reuse.
https://www.dartdocs.org/documentation/postgres/latest
BSD 3-Clause "New" or "Revised" License
129 stars 32 forks source link

Hangs on errors. #151

Closed AerLiberum closed 3 years ago

AerLiberum commented 3 years ago

May be I am just a newbie, but I think, that ur library is written very bad, because it doesn't handle possible errors. For example here it just hangs on my empty database with an error: "PostgreSQLSeverity.error 42P01: relation "users" does not exist" on this line: "List<List> results = await conn.query('SELECT * FROM users');" It doesn't go forward, doesn't return an exception for me to catch. I don't know what to do here. Such mistakes with bad requests can appear in any place and stop the server that I write.


PostgreSQLConnection conn;
  try {
    var db = DBPostgres(
      address: config['dbAddress'],
      port: config['dbPort'],
      dbname: config['dbName'],
      username: config['dbUser'],
      password: config['dbPassword'],
    );
    await db.connect().then((connection) => conn = connection);
    List<List<dynamic>> results = await conn.query('SELECT * FROM users');
    print(results);
    await conn.close();
  } catch (e) {
    log.e(e);
  }