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

@@ -10,14 +10,8 @@ var Args = os.Args[1:]
type stack = []ArObject type stack = []ArObject
const VERSION = "3.0.4-2" const VERSION = "3.0.4-3"
const VERSION_NUM = 1 const VERSION_NUM = 2
// Example struct
type Person struct {
Name string
Age int
}
func newscope() ArObject { func newscope() ArObject {
return Map(anymap{}) return Map(anymap{})

View File

@@ -14,7 +14,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "ReadDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -22,7 +22,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "ReadDir argument must be a string, got " + typeof(args[0]), message: "ReadDir argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -30,7 +30,7 @@ var ArPath = Map(
files, err := os.ReadDir(args[0].(string)) files, err := os.ReadDir(args[0].(string))
if err != nil { if err != nil {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: err.Error(), message: err.Error(),
EXISTS: true, EXISTS: true,
} }
@@ -46,7 +46,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "exists takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "exists takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -54,7 +54,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "exists argument must be a string, got " + typeof(args[0]), message: "exists argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -65,7 +65,7 @@ var ArPath = Map(
return false, ArErr{} return false, ArErr{}
} }
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: err.Error(), message: err.Error(),
EXISTS: true, EXISTS: true,
} }
@@ -77,7 +77,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "mkAllDir takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "mkAllDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -85,7 +85,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "mkAllDir argument must be a string, got " + typeof(args[0]), message: "mkAllDir argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -93,7 +93,7 @@ var ArPath = Map(
err := os.MkdirAll(args[0].(string), os.ModePerm) err := os.MkdirAll(args[0].(string), os.ModePerm)
if err != nil { if err != nil {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: err.Error(), message: err.Error(),
EXISTS: true, EXISTS: true,
} }
@@ -105,7 +105,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "mkDir takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "mkDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -113,7 +113,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "mkDir argument must be a string, got " + typeof(args[0]), message: "mkDir argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -121,7 +121,7 @@ var ArPath = Map(
err := os.Mkdir(args[0].(string), os.ModePerm) err := os.Mkdir(args[0].(string), os.ModePerm)
if err != nil { if err != nil {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: err.Error(), message: err.Error(),
EXISTS: true, EXISTS: true,
} }
@@ -133,7 +133,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "remove takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "remove takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -141,7 +141,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "remove argument must be a string, got " + typeof(args[0]), message: "remove argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -149,7 +149,7 @@ var ArPath = Map(
err := os.Remove(args[0].(string)) err := os.Remove(args[0].(string))
if err != nil { if err != nil {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: err.Error(), message: err.Error(),
EXISTS: true, EXISTS: true,
} }
@@ -161,7 +161,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "isDir takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "isDir takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -169,7 +169,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "isDir argument must be a string, got " + typeof(args[0]), message: "isDir argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -180,7 +180,7 @@ var ArPath = Map(
return false, ArErr{} return false, ArErr{}
} }
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: err.Error(), message: err.Error(),
EXISTS: true, EXISTS: true,
} }
@@ -192,7 +192,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "join takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -205,7 +205,7 @@ var ArPath = Map(
x = ArValidToAny(x) x = ArValidToAny(x)
if typeof(x) != "string" { if typeof(x) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "join argument must be an array of strings, got " + typeof(x), message: "join argument must be an array of strings, got " + typeof(x),
EXISTS: true, EXISTS: true,
} }
@@ -215,7 +215,7 @@ var ArPath = Map(
return filepath.Join(Path...), ArErr{} return filepath.Join(Path...), ArErr{}
} }
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "join argument must be an array, got " + typeof(args[0]), message: "join argument must be an array, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }
@@ -225,7 +225,7 @@ var ArPath = Map(
func(args ...any) (any, ArErr) { func(args ...any) (any, ArErr) {
if len(args) != 1 { if len(args) != 1 {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "parent takes exactly 1 argument, got " + fmt.Sprint(len(args)), message: "parent takes exactly 1 argument, got " + fmt.Sprint(len(args)),
EXISTS: true, EXISTS: true,
} }
@@ -233,7 +233,7 @@ var ArPath = Map(
args[0] = ArValidToAny(args[0]) args[0] = ArValidToAny(args[0])
if typeof(args[0]) != "string" { if typeof(args[0]) != "string" {
return nil, ArErr{ return nil, ArErr{
TYPE: "runtime", TYPE: "Runtime Error",
message: "parent argument must be a string, got " + typeof(args[0]), message: "parent argument must be a string, got " + typeof(args[0]),
EXISTS: true, EXISTS: true,
} }