fnproject / fdk-go

Go language helper funcs for fn
Apache License 2.0
25 stars 15 forks source link

Enhance error prompt while running go fn app locally #28

Open bluezd opened 6 years ago

bluezd commented 6 years ago
# fn init --runtime go hello
# go run func.go
panic: unknown format (fdk-go):

goroutine 1 [running]:
github.com/fnproject/fdk-go/utils.Do(0x14b3070, 0x128e178, 0x0, 0x0, 0x1380fe0, 0xc42000e010, 0x1381020, 0xc42000e018)
    /Users/jude/Programing/Go/Libraries/src/github.com/fnproject/fdk-go/utils/utils.go:51 +0x193
github.com/fnproject/fdk-go.Handle(0x1381a60, 0x128e178)
    /Users/jude/Programing/Go/Libraries/src/github.com/fnproject/fdk-go/fdk.go:81 +0xce
main.main()
    /Users/jude/Working/Oracle/Fn/apps/hello/func.go:14 +0x39
exit status 2

Fixing this issue is simple:

# export FN_FORMAT="default"
# echo '{"name": "Johnny"}' | ./func
{"message":"Hello Johnny"}

However for users who are totally new to the fn project they usually have no idea about what is going wrong there . They just wanna make sure their function works properly locally before building a fn app.

Shall we develop a patch in go FDK side for telling user what is going wrong there and how to fix it rather that a panic without any prompt ?

denismakogon commented 6 years ago

Hi and welcome! Here's the thing. You actually allocated problematic area very explicitly, however, it not related to fdk-go. If you'd like to test your function, you need to use the following commands:

fn test

or

fn run

Because the format env var is not the only var you'd need to set (there are at least 6 to 10 env vars FDK would need).

So, the thing you've done is not typic or even recommended path go. I recommend you to spend some time playing with interactive tutorial here: https://www.katacoda.com/fnproject/scenarios/fn-intro

bluezd commented 6 years ago

I did fn test and fn run and it behaves normally. I am just wondering how to test the function locally, as you said it is not recommended. I got it. Thanks.

denismakogon commented 6 years ago

Well. There have to be 2 ways to test your function:

So, FDK-go misses the 2nd point. I'd better rename this issue to something in lines to:

Provide Go native testing framework for functions for sake of better coverage
bluezd commented 6 years ago

Sure, agree.