Improved debuglogs and error messages, misc. parsing improvements, dependency updates

master
Sven Slootweg 3 years ago
parent 899ea8dab9
commit 882ede36ed

@ -0,0 +1,2 @@
error: invalid input syntax for type timestamp with time zone: "{}"
insert into "transaction_events" ("field", "operator_id", "origin", "transaction_id", "type", "value") values ($1, DEFAULT, $2, $3, $4, $5), ($6, DEFAULT, $7, $8, $9, $10), ($11, DEFAULT, $12, $13, $14, $15), ($16, DEFAULT, $17, $18, $19, $20), ($21, DEFAULT, $22, $23, $24, $25), ($26, DEFAULT, $27, $28, $29, $30), ($31, DEFAULT, $32, $33, $34, $35), ($36, DEFAULT, $37, $38, $39, $40), ($41, DEFAULT, $42, $43, $44, $45), ($46, DEFAULT, $47, $48, $49, $50), ($51, DEFAULT, $52, $53, $54, $55), ($56, DEFAULT, $57, $58, $59, $60), ($61, DEFAULT, $62, $63, $64, $65), ($66, DEFAULT, $67, $68, $69, $70), ($71, DEFAULT, $72, $73, $74, DEFAULT) returning * - invalid input syntax for type json

@ -23,14 +23,15 @@
"license": "WTFPL",
"dependencies": {
"create-error": "^0.3.1",
"debug": "^4.1.1",
"pg-error-codes": "^1.0.0"
},
"devDependencies": {
"@joepie91/gulp-preset-es2015": "^1.0.1",
"babel-preset-es2015": "^6.6.0",
"bluebird": "^3.4.6",
"babel-preset-es2015": "^6.24.1",
"bluebird": "^3.5.1",
"gulp": "^3.9.1",
"knex": "^0.12.6",
"pg": "^6.1.0"
"knex": "^0.12.9",
"pg": "^6.4.2"
}
}

@ -9,7 +9,7 @@ const getTable = require("../get-table");
let InvalidTypeError = createError(DatabaseError, "InvalidTypeError");
/* NOTE: error messages vary. Eg. for boolean-type columns, it states "for type boolean", but for integer-type columns, it starts "for integer". */
let messageRegex = /^(.+) - invalid input syntax for(?: type)? ([^:]+): "([^"]+)"$/;
let messageRegex = /^(?:(.+) - )?invalid input syntax for(?: type)? ([^:]+)(?:: "(.+)")?$/;
module.exports = {
error: InvalidTypeError,
@ -24,7 +24,8 @@ module.exports = {
let messageMatch = messageRegex.exec(error.message);
if (messageMatch == null) {
throw new Error("Encountered unknown error format");
/* TODO: Update other error parsing modules to display the original error message here as well. */
throw new Error(`Encountered unknown error format for error message: ${error.message}`);
}
let [_, query, expectedType, value] = messageMatch;
@ -32,10 +33,11 @@ module.exports = {
let message;
/* TODO: `value` can be undefined! */
if (table != null) {
message = `Value '${value}' is of the wrong type for a '${expectedType}'-type column (in table '${table}')`;
message = `Value <${value}> is of the wrong type for a '${expectedType}'-type column (in table '${table}')`;
} else {
message = `Value '${value}' is of the wrong type for a '${expectedType}'-type column '${enumType}'`;
message = `Value <${value}> is of the wrong type for a '${expectedType}'-type column`;
}
return new InvalidTypeError(message, {

@ -8,7 +8,7 @@ const getTable = require("../get-table");
let UndefinedColumnError = createError(DatabaseError, "UndefinedColumnError");
let messageRegex = /^(.+) - column "([^"]+)" of relation "([^"]+)" does not exist$/;
let messageRegex = /^(.+) - column "([^"]+)" (?:of relation "([^"]+)" )?does not exist$/;
module.exports = {
error: UndefinedColumnError,
@ -28,7 +28,16 @@ module.exports = {
let [_, query, column, table] = messageMatch;
return new UndefinedColumnError(`The '${column}' column does not exist in the '${table}' table`, {
let errorMessage;
if (table != null) {
errorMessage = `The '${column}' column does not exist in the '${table}' table`;
} else {
/* TODO: Maybe try to extract this from the query... somehow? */
errorMessage = `The '${column}' column does not exist in (unknown table)`;
}
return new UndefinedColumnError(errorMessage, {
originalError: error,
pgCode: error.code,
code: pgErrorCodes[error.code],

@ -1,6 +1,6 @@
'use strict';
let detailsRegex = /^Failing row contains \(([^\)]+)\).$/;
let detailsRegex = /^Failing row contains \((.+)\).$/;
module.exports = function getValues(detail) {
let detailsMatch = detailsRegex.exec(detail);

@ -1,6 +1,7 @@
'use strict';
const createError = require("create-error");
const debug = require("debug")("database-error");
const DatabaseError = require("./database-error");
@ -20,6 +21,7 @@ function convertError(error) {
let handler = handlers.find(handler => handler.check(error));
if (handler != null) {
debug(`Converting error with message: ${error.message}`)
return handler.convert(error);
} else {
throw new UnknownError("The specified error is not of a recognized type");

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save