Skip to content

Commit b593b61

Browse files
author
Oppiie
authored
Added optional capture group for error position (#39)
* Added optional capture group for error position * Replaced regex spaces with universal space match + removed newlines from error msg
1 parent 9e02111 commit b593b61

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

aurora_data_api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
logger = logging.getLogger(__name__)
3838

39-
postgresql_error_reg = re.compile(r'^ERROR: (.*)[\s+]+Position: ([0-9]+); SQLState: ([0-9A-Z]+)$')
39+
postgresql_error_reg = re.compile(r'^ERROR:\s(.*)\s(?:[\s+]+Position:\s([0-9]+);\s)?SQLState:\s([0-9A-Z]+)$')
4040

4141

4242
class AuroraDataAPIClient:
@@ -219,7 +219,7 @@ def _get_database_error(self, origin_error):
219219
code, msg = (s.split(": ", 1)[1] for s in error_msg.split(". ", 1))
220220
return DatabaseError(MySQLErrorCodes(int(code)), msg)
221221
elif error_msg.startswith("ERROR: "): # Postgresql error
222-
msg, pos, code = postgresql_error_reg.match(error_msg).groups()
222+
msg, pos, code = postgresql_error_reg.match(error_msg.replace('\n', '')).groups()
223223
return DatabaseError(PostgreSQLErrorCodes(code), msg, pos)
224224
except Exception:
225225
pass

0 commit comments

Comments
 (0)