mirror of
https://github.com/maputnik/editor.git
synced 2026-08-26 15:07:41 +00:00
add error handling
This commit is contained in:
@@ -16,12 +16,27 @@ CodeMirror.defineMode("mgl", (config, parserConfig) => {
|
|||||||
|
|
||||||
CodeMirror.registerHelper("lint", "json", (text: string) => {
|
CodeMirror.registerHelper("lint", "json", (text: string) => {
|
||||||
const found: MarkerRangeWithMessage[] = [];
|
const found: MarkerRangeWithMessage[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parse(text);
|
parse(text);
|
||||||
}
|
}
|
||||||
catch(_e) {
|
catch(err: any) {
|
||||||
// Do nothing we catch the error above
|
|
||||||
|
const errorMatch = err.toString().match(/line (\d+), column (\d+)/);
|
||||||
|
if (errorMatch) {
|
||||||
|
const loc = {
|
||||||
|
first_line: parseInt(errorMatch[1], 10),
|
||||||
|
first_column: parseInt(errorMatch[2], 10),
|
||||||
|
last_line: parseInt(errorMatch[1], 10),
|
||||||
|
last_column: parseInt(errorMatch[2], 10)
|
||||||
|
};
|
||||||
|
|
||||||
|
// const loc = hash.loc;
|
||||||
|
found.push({
|
||||||
|
from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
||||||
|
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
||||||
|
message: err
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
});
|
});
|
||||||
@@ -33,8 +48,25 @@ CodeMirror.registerHelper("lint", "mgl", (text: string, opts: any, doc: any) =>
|
|||||||
try {
|
try {
|
||||||
parse(text);
|
parse(text);
|
||||||
}
|
}
|
||||||
catch (_e) {
|
catch (err: any) {
|
||||||
// ignore errors
|
|
||||||
|
const errorMatch = err.toString().match(/line (\d+), column (\d+)/);
|
||||||
|
if (errorMatch) {
|
||||||
|
const loc = {
|
||||||
|
first_line: parseInt(errorMatch[1], 10),
|
||||||
|
first_column: parseInt(errorMatch[2], 10),
|
||||||
|
last_line: parseInt(errorMatch[1], 10),
|
||||||
|
last_column: parseInt(errorMatch[2], 10)
|
||||||
|
};
|
||||||
|
|
||||||
|
// const loc = hash.loc;
|
||||||
|
found.push({
|
||||||
|
from: CodeMirror.Pos(loc.first_line - 1, loc.first_column),
|
||||||
|
to: CodeMirror.Pos(loc.last_line - 1, loc.last_column),
|
||||||
|
message: err
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found.length > 0) {
|
if (found.length > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user