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

Fix/better errors #848

Merged
merged 4 commits into from Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/parser/errors.ts
Expand Up @@ -270,11 +270,11 @@ export var messages = {
unimplementedExpression: (op:string) => `There's no definition for the function ${op}`,

blankScan: () => 'Lookup requires at least one attribute: record, attribute, value, or node',
invalidLookupAction: (missing:string[]) => `Updating a lookup requires that record, attribute, and value all be provided. Looks like ${missing.join("and")} is missing.`,
invalidLookupAction: (missing:string[]) => `Updating a lookup requires that record, attribute, and value all be provided. Looks like ${missing.join("and")} ${missing.length > 1 ? "are" : "is"} missing.`,

neverEqual: (left:string, right:string) => `${left} can never equal ${right}`,
variableNeverEqual: (variable:any, value:string, right:string) => `${variable.name} is equivalent to ${value}, which can't be equal to ${right}`,

actionNonTag: (found:string) => `Looks like this should be a tag, try changing the ${found} to a #`,
actionRawIdentifier: (found:string) => `I can only add/remove tags directly on a record. If you meant to add ${found} as an attribute to the record, try 'my-record.found += ${found}'; if you meant to add the #${found} tag, add #.`
actionNonTag: (found:string) => `Looks like this should be a tag, try changing the ${found} to #${found}`,
actionRawIdentifier: (found:string) => `I can only add/remove tags directly on a record. If you meant to add ${found} as an attribute to the record, try 'my-record.${found} += ${found}'; if you meant to add the #${found} tag, add #.`
};
12 changes: 6 additions & 6 deletions src/parser/parser.ts
Expand Up @@ -1491,6 +1491,8 @@ export function errorToFacts(eavs:any[], error:EveError, block:any) {
let pos = 0;
let start = error.start - offset;
let stop = error.stop - offset;
if(isNaN(stop)) stop = text.length + offset;
if(isNaN(start)) start = offset;
let curLine = 0;
let startLine = 0;
let startChar = 0;
Expand All @@ -1500,19 +1502,17 @@ export function errorToFacts(eavs:any[], error:EveError, block:any) {
pos += blockLines[curLine++].length + 1;
}
startLine = blockStartLine + curLine;
startChar = start - (pos - blockLines[curLine - 1].length) + 2;
startChar = start - (pos - (blockLines[curLine - 1] || "").length) + 2;
while(curLine < blockLines.length && pos < stop) {
pos += blockLines[curLine++].length + 1;
pos += (blockLines[curLine++] || "").length + 1;
}
stopLine = blockStartLine + curLine;
stopChar = stop - (pos - blockLines[curLine - 1].length) + 2;
stopChar = stop - (pos - (blockLines[curLine - 1] || "").length) + 2;

let sampleText = [];
let relativeStart = startLine - blockStartLine;
let relativeStop = stopLine - blockStartLine;
if(relativeStart === 0) {
sampleText.push(blockLines[0]);
} else {
if(relativeStart != 0) {
sampleText.push(blockLines[relativeStart - 1]);
sampleText.push(blockLines[relativeStart]);
}
Expand Down