-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better error logging #86
Conversation
lib/db.js
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
position
is guaranteed to be at least 0
startLineWrapPos
is also guaranteed to be at least 0 (so the with Math.max doesn't seem to make sense?)
assuming position
>= startLineWrapPos
.
so overall the parameter passed to report is at least (0 - 0 - 1) = (-1).
' '.repeat(-1) throws exception both in browser and in node.js
so I think the Math.max test should be around all of that, i.e.
' '.repeat(Math.max(position - startLineWrapPos - 1, 0))
... or did I miss anything here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Position should be >=1 because SQL indexing starts with 1, and Math.max is really redundant.
lib/db.js
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is
const startLineIndexOf = stringStart.lastIndexOf('\n');
const startLineWrapPos = startLineIndexOf >= 0 ? startLineIndexOf + 1 : 0;
Because we want to start AFTER \n
or on first character...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.