fix up inconsistent error types

This commit is contained in:
2024-04-09 19:22:43 +01:00
parent 42e12933bf
commit a8fb5d4c1f
15 changed files with 273 additions and 279 deletions

View File

@@ -9,19 +9,19 @@ var threadChan = make(chan bool)
func ArThread(args ...any) (any, ArErr) {
if len(args) != 1 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 1, got " + fmt.Sprint(len(args)), EXISTS: true}
}
var tocall any
switch x := args[0].(type) {
case anymap:
if _, ok := x["__call__"]; !ok {
return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
}
tocall = x["__call__"]
case builtinFunc, Callable:
tocall = x
default:
return nil, ArErr{TYPE: "TypeError", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Cannot call thread with a '" + typeof(args[0]) + "'", EXISTS: true}
}
var resp any
var err ArErr
@@ -35,7 +35,7 @@ func ArThread(args ...any) (any, ArErr) {
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot start a thread twice", EXISTS: true}
}
if len(args) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
}
hasrun = true
threadCount++
@@ -56,7 +56,7 @@ func ArThread(args ...any) (any, ArErr) {
return nil, ArErr{TYPE: "Runtime Error", message: "Cannot join a thread twice", EXISTS: true}
}
if len(args) != 0 {
return nil, ArErr{TYPE: "TypeError", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
return nil, ArErr{TYPE: "Type Error", message: "Invalid number of arguments, expected 0, got " + fmt.Sprint(len(args)), EXISTS: true}
}
joined = true
<-wg