Skip to content
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

Merged
merged 2 commits into from
May 22, 2017
Merged

Better error logging #86

merged 2 commits into from
May 22, 2017

Conversation

dolezel
Copy link
Contributor

@dolezel dolezel commented May 19, 2017

No description provided.

@dolezel dolezel requested a review from roman-kaspar May 19, 2017 07:37
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);

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?

Copy link
Contributor Author

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;
Copy link
Contributor Author

@dolezel dolezel May 22, 2017

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...

Copy link

@roman-kaspar roman-kaspar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dolezel dolezel merged commit af94e8f into master May 22, 2017
@dolezel dolezel deleted the error_logging branch May 22, 2017 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants