Skip to content

Commit 54f47f0

Browse files
committed
error handler update
1 parent dc7dc93 commit 54f47f0

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

examples/main.bug

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
import "examples.routes.routes";
2-
import "json";
1+
// import "examples.routes.routes";
2+
// import "json";
33

4-
r = new routes.Routes();
54

6-
func test(){
7-
return {"detail": "ok"}
8-
}
5+
var names = [1,2];
96

10-
r.register("test", test, 10);
11-
print(json.encode(r.list()["test"]()));
7+
names.appnd(3);
8+
println(names);
9+
10+
11+
12+
// r = new routes.Routes();
13+
14+
// func test(){
15+
// return {"detail": "ok"}
16+
// }
17+
18+
// r.register("test", test, 10);
19+
// print(json.encode(r.list()["test"]()));

examples/routes/routes.bug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Routes(){
66
}
77

88
func register(path, fn, ds){
9-
this.rr.add(path, fn);
9+
this.rr.append(path, fn);
1010
}
1111

1212
func list(){

internal/runtime/interpreter.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,11 @@ func EvalMemberExpression(node *parser.MemberNode, env *enviroment.Enviroment) (
297297
return t.Enviroment.GetVariable(prop, node.Line)
298298
case types.Object:
299299
v := reflect.ValueOf(left)
300-
return v.MethodByName(string(strings.ToUpper(prop[:1]) + prop[1:])), nil
300+
method := v.MethodByName(string(strings.ToUpper(prop[:1]) + prop[1:]))
301+
if !method.IsValid() {
302+
return nil, fmt.Errorf("method %s not found in %T line: %d", prop, t, node.Line)
303+
}
304+
return method, nil
301305
case *enviroment.Enviroment:
302306
return t.GetVariable(prop, node.Line)
303307
default:

0 commit comments

Comments
 (0)