Skip to content

Commit 5197f43

Browse files
committed
fix(sdk): adding line number to parse errors
1 parent 0355677 commit 5197f43

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

runner/src/main/resources/view/lib/Parser.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,14 @@ Parser.prototype.read = function (input, n) {
106106
const type = typeValue[1]
107107
if (!/^[a-zA-Z0-9]+$/.test(name)) {
108108
throw new ParseError('InvalidVariable', {
109-
variable: name
109+
variable: name,
110+
line: this.getLineNumber()
110111
})
111112
}
112113
if (!type) {
113114
throw new ParseError('MissingType', {
114-
variable: name
115+
variable: name,
116+
line: this.getLineNumber()
115117
})
116118
}
117119
const nType = new Node(type, n)
@@ -125,12 +127,14 @@ Parser.prototype.read = function (input, n) {
125127
} else if (type === 'word' || type === 'string') {
126128
throw new ParseError('MissingLength', {
127129
variable: name,
128-
type: type
130+
type: type,
131+
line: this.getLineNumber()
129132
})
130133
} else if (this.allowType.indexOf(type) < 0) {
131134
throw new ParseError('InvalidType', {
132135
variable: name,
133-
type: type
136+
type: type,
137+
line: this.getLineNumber()
134138
})
135139
}
136140

@@ -155,7 +159,8 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
155159

156160
if (typeof param !== 'undefined') {
157161
throw new ParseError('InvalidKeyword', {
158-
param: cmd + ':' + param
162+
param: cmd + ':' + param,
163+
line: this.getLineNumber()
159164
})
160165
}
161166

@@ -300,7 +305,8 @@ Parser.prototype.parseTree = function (node, input, loopCnt) {
300305
}
301306
default:
302307
throw new ParseError('InvalidKeyword', {
303-
param: cmd
308+
param: cmd,
309+
line: this.getLineNumber()
304310
})
305311
}
306312
}
@@ -336,5 +342,8 @@ Parser.prototype.extractParam = function (type) {
336342
const iclose = type.indexOf(')')
337343
return type.substring(iopen + 1, iclose)
338344
}
345+
Parser.prototype.getLineNumber = function () {
346+
return this.code.substring(0, this.cursor - 1).split('').filter(r => r === '\n').length + 1
347+
}
339348

340349
export default Parser

0 commit comments

Comments
 (0)