From effc043adc730041d1374a99d21052410412eeb6 Mon Sep 17 00:00:00 2001 From: Jan Dolezel Date: Fri, 19 May 2017 09:37:03 +0200 Subject: [PATCH 1/2] Better error logging --- lib/db.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/db.js b/lib/db.js index 786cb30c..24a8a43c 100644 --- a/lib/db.js +++ b/lib/db.js @@ -35,7 +35,30 @@ export default (connection_string) => { : resolve(result) )) ) - ); + ) + .catch(err => { + const { message, position } = err; + if (message && position >= 0) { + const endLineWrapIndexOf = string.indexOf('\n', position); + const endLineWrapPos = endLineWrapIndexOf >= 0 ? endLineWrapIndexOf : string.length; + const stringStart = string.substring(0, endLineWrapPos); + const stringEnd = string.substr(endLineWrapPos); + const startLineWrapPos = stringStart.lastIndexOf('\n') + 1; + const padding = ' '.repeat(position - Math.max(startLineWrapPos, 0) - 1); + console.error(`Error executing: +${stringStart} +${padding}^^^^${stringEnd} + +${message} +`); + } else { + console.error(`Error executing: +${string} +${err} +`); + } + throw err; + }); const select = string => query(string) From fe4976c781cba17dcc9a8eb31cb9feb382e932fc Mon Sep 17 00:00:00 2001 From: Jan Dolezel Date: Mon, 22 May 2017 09:26:52 +0200 Subject: [PATCH 2/2] Proper index counting --- lib/db.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/db.js b/lib/db.js index 24a8a43c..2150e3fc 100644 --- a/lib/db.js +++ b/lib/db.js @@ -38,13 +38,13 @@ export default (connection_string) => { ) .catch(err => { const { message, position } = err; - if (message && position >= 0) { + if (message && position >= 1) { const endLineWrapIndexOf = string.indexOf('\n', position); const endLineWrapPos = endLineWrapIndexOf >= 0 ? endLineWrapIndexOf : string.length; const stringStart = string.substring(0, endLineWrapPos); const stringEnd = string.substr(endLineWrapPos); const startLineWrapPos = stringStart.lastIndexOf('\n') + 1; - const padding = ' '.repeat(position - Math.max(startLineWrapPos, 0) - 1); + const padding = ' '.repeat(position - startLineWrapPos - 1); console.error(`Error executing: ${stringStart} ${padding}^^^^${stringEnd}