throw real errors

This commit is contained in:
Chris Wanstrath 2025-10-26 12:25:34 -07:00
parent bf6607d368
commit e300946c48
2 changed files with 5 additions and 4 deletions

View File

@ -61,7 +61,7 @@ export function toValue(v: any): Value /* throws */ {
case 'string':
return { type: 'string', value: v }
case 'function':
throw "can't toValue() a js function yet"
throw new Error("can't toValue() a js function yet")
case 'object':
const dict: Dict = new Map()
@ -69,7 +69,7 @@ export function toValue(v: any): Value /* throws */ {
return { type: 'dict', value: dict }
default:
throw `can't toValue this: ${v}`
throw new Error(`can't toValue this: ${v}`)
}
}

View File

@ -37,7 +37,8 @@ export class VM {
const value = this.scope.get(name)
if (!value) throw new Error(`Can't find ${name}`)
if (value.type !== 'function' && value.type !== 'native') throw new Error(`Can't call ${name}`)
if (value.type !== 'function' && value.type !== 'native')
throw new Error(`Can't call ${name}`)
if (value.type === 'native') {
return await this.callNative(value.fn, args)
@ -725,7 +726,7 @@ export class VM {
break
default:
throw `Unknown op: ${instruction.op}`
throw new Error(`Unknown op: ${instruction.op}`)
}
}