Skip to content

Bug: 40+ error messages use .Type() directly, leaking internal Go type names #948

@SchoolyB

Description

@SchoolyB

Description

Throughout evaluator.go and stdlib/, .Type() is called directly in error messages instead of using getEZTypeName(). This causes internal Go type names like INTEGER_OBJ, MAP_OBJ, STRING_OBJ to appear in user-facing errors.

Examples

User sees:

error: index must be an integer, got FLOAT_OBJ
error: unknown operator: STRING_OBJ + INTEGER_OBJ
error: len() not supported for MAP_OBJ

Should see:

error: index must be an integer, got float
error: unknown operator: string + int
error: len() not supported for map[string:int]

Affected Locations

pkg/interpreter/evaluator.go (~30 instances):

  • Line 661: "unusable as map key: %s", index.Type()
  • Line 684: "index must be an integer, got %s", index.Type()
  • Line 721: "index operator not supported for %s", left.Type()
  • Line 1159: "cannot assign %s to byte variable", unpackedVal.Type()
  • Line 1297: "array index must be integer, got %s", idx.Type()
  • Line 1345: "string index must be integer, got %s", idx.Type()
  • Line 1375: "map key must be a hashable type, got %s", idx.Type()
  • Line 1451: "member access not supported: %s", obj.Type()
  • Line 1755: "range start must be integer, got %s", startObj.Type()
  • Line 2012: "for_each requires array or string, got %s", collection.Type()
  • Line 2223: "unknown operator: %s%s", operator, right.Type()
  • Line 2320: "unknown operator: %s %s %s", left.Type(), operator, right.Type()
  • Line 2599: "left operand of 'in range()' must be integer, got %s", left.Type()
  • Line 2668: "postfix operator %s requires integer operand, got %s", node.Operator, val.Type()
  • Line 2972: "not a function: %s", fn.Type()
  • Line 3642: "member access not supported on type %s", obj.Type()
  • Plus ~15 more similar instances

pkg/stdlib/ (~10 instances):

  • builtins.go:347: "len() not supported for %s", args[0].Type()
  • builtins.go:472: "cannot convert %s to int", args[0].Type()
  • builtins.go:516: "cannot convert %s to float", args[0].Type()
  • builtins.go:570: "cannot convert %s to char", args[0].Type()
  • builtins.go:634: "cannot convert %s to byte", args[0].Type()
  • math.go:946: "expected number, got %s", obj.Type()
  • json.go:241: "JSON object keys must be strings, got %s", pair.Key.Type()
  • json.go:300: "type %s cannot be converted to JSON", obj.Type()

Fix

Replace all .Type() calls in error messages with getEZTypeName() or objectTypeToEZ():

// Before
"index must be an integer, got %s", index.Type()

// After  
"index must be an integer, got %s", getEZTypeName(index)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingerror-messagesRelated to improving error messagesinterpreterRelated to evaluation and runtime executionstdlibGeneral standard library issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions