Throw errors properly

Test plan:
  - All existing tests pass

flag=none

Refs DE-1426

Change-Id: I7b5d0e12cd2ad9f36f0d2a454ff7b2d5db5195b1
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/303337
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Spencer Olson <solson@instructure.com>
Product-Review: Cameron Ray <cameron.ray@instructure.com>
QA-Review: Aaron Shafovaloff <ashafovaloff@instructure.com>
This commit is contained in:
Aaron Shafovaloff 2022-10-15 07:19:37 -06:00
parent 484e2b2734
commit eb2711d52e
3 changed files with 15 additions and 14 deletions

View File

@ -68,7 +68,7 @@ const calcCmd = {}
while (index < command.length) {
const item = parseToken(command, index)
if (!item) {
throw 'unrecognized token at ' + index
throw new Error('unrecognized token at ' + index)
}
index = item.newIndex
result.push(item)
@ -92,7 +92,7 @@ const calcCmd = {}
syntaxIndex++
result = syntax[syntaxIndex]
} else {
throw 'expecting a number at ' + syntax[syntaxIndex].newIndex
throw new Error('expecting a number at ' + syntax[syntaxIndex].newIndex)
}
break
case 'variable':
@ -113,7 +113,7 @@ const calcCmd = {}
}
syntaxIndex--
if (ender !== 'close_paren') {
throw 'expecting close parenthesis at ' + syntax[syntaxIndex].newIndex
throw new Error('expecting close parenthesis at ' + syntax[syntaxIndex].newIndex)
}
} else {
result = syntax[syntaxIndex]
@ -129,7 +129,7 @@ const calcCmd = {}
if (!result) {
const index = (syntax && syntax[syntaxIndex] && syntax[syntaxIndex].newIndex) || 0
const type = (syntax && syntax[syntaxIndex] && syntax[syntaxIndex].token) || 'nothing'
throw 'expecting a value at ' + index + ', got a ' + type
throw new Error('expecting a value at ' + index + ', got a ' + type)
}
syntaxIndex++
return result
@ -149,7 +149,7 @@ const calcCmd = {}
}
const value = (syntax && syntax[syntaxIndex] && syntax[syntaxIndex].token) || 'value'
const index = (syntax && syntax[syntaxIndex] && syntax[syntaxIndex].newIndex) || 0
throw 'unexpected ' + value + ' at ' + index
throw new Error('unexpected ' + value + ' at ' + index)
}
var parseExpression = function (syntax, enders) {
@ -200,7 +200,7 @@ const calcCmd = {}
syntaxIndex = 2
result.assignmentExpression = parseExpression(syntax)
} else {
throw 'Expecting value at ' + syntax[syntaxIndex + 1].newIndex
throw new Error('Expecting value at ' + syntax[syntaxIndex + 1].newIndex)
}
} else {
result = parseExpression(syntax)
@ -254,9 +254,9 @@ const calcCmd = {}
}
}
if (round3.length === 0) {
throw 'expressions should have at least one value'
throw new Error('expressions should have at least one value')
} else if (round3.length > 1) {
throw 'unexpected modifier: ' + round3[1].token
throw new Error('unexpected modifier: ' + round3[1].token)
} else {
return compute(round3[0])
}
@ -278,7 +278,7 @@ const calcCmd = {}
return compute(tree.expression)
case 'variable_assignment':
if (tree.variable.value === '_') {
throw "the variable '_' is reserved"
throw new Error("the variable '_' is reserved")
}
variables[tree.variable.value] = compute(tree.assignmentExpression)
return variables[tree.variable.value]
@ -297,7 +297,7 @@ const calcCmd = {}
value = value || (variables && variables[tree.value])
}
if (value == undefined) {
throw 'undefined variable ' + tree.value
throw new Error('undefined variable ' + tree.value)
}
return value
case 'method':
@ -310,10 +310,10 @@ const calcCmd = {}
if (methods[tree.value]) {
return methods[tree.value].apply(null, args)
} else {
throw 'unrecognized method ' + tree.value
throw new Error('unrecognized method ' + tree.value)
}
}
throw 'Unexpected token type: ' + tree.token
throw new Error('Unexpected token type: ' + tree.token)
}
calcCmd.clearMemory = function () {
variables = {}

View File

@ -42,7 +42,7 @@ function legacyContentItem(ltiAdvantageContentItem) {
const legacyType = types[type]
if (!legacyType) {
throw `Unknown type: ${type}`
throw new Error(`Unknown type: ${type}`)
}
const contentItem = {

View File

@ -47,7 +47,8 @@ export default class WikiPageCollection extends PaginatedCollection {
}
setSortField(sortField, sortOrder = null) {
if (this.sortOrders[sortField] === undefined) throw `${sortField} is not a valid sort field`
if (this.sortOrders[sortField] === undefined)
throw new Error(`${sortField} is not a valid sort field`)
// toggle the sort order if no sort order is specified and the sort field is the current sort field
if (!sortOrder && this.currentSortField === sortField) {