Skip to content

Commit 4a70d32

Browse files
committed

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

polycode/config.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,26 @@ package polycode
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
)
78

89
type AppConfig map[string]interface{}
910

10-
func FromAppConfig(ctx context.Context, configObj any) {
11-
srvCtx, ok := ctx.(ServiceContext)
11+
func FromAppConfig(ctx context.Context, configObj any) error {
12+
baseCtx, ok := ctx.(BaseContext)
1213
if ok {
13-
ret := srvCtx.AppConfig()
14+
ret := baseCtx.AppConfig()
1415
b, err := json.Marshal(configObj)
1516
if err != nil {
16-
panic(err)
17-
}
18-
err = json.Unmarshal(b, &ret)
19-
if err != nil {
20-
panic(err)
21-
}
22-
return
23-
}
24-
wkfCtx, ok := ctx.(WorkflowContext)
25-
if ok {
26-
ret := wkfCtx.AppConfig()
27-
b, err := json.Marshal(configObj)
28-
if err != nil {
29-
panic(err)
17+
return err
3018
}
19+
3120
err = json.Unmarshal(b, &ret)
3221
if err != nil {
33-
panic(err)
22+
return err
3423
}
35-
return
24+
return nil
3625
}
37-
panic("invalid context")
26+
27+
return errors.New("invalid context")
3828
}

polycode/env.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package polycode
22

33
import (
44
"fmt"
5-
"log"
65
"os"
76
)
87

@@ -21,7 +20,7 @@ func InitClientEnv() {
2120
var appPort uint
2221
_, err := fmt.Sscanf(appPortStr, "%d", &appPort)
2322
if err != nil {
24-
log.Fatalf("invalid APP_PORT: %s", appPortStr)
23+
appPort = 9998
2524
}
2625

2726
clientEnv = &ClientEnv{

polycode/runtime.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,13 @@ func loadAppConfig() AppConfig {
8181
log.Println("client: application.yml not found. generating empty config")
8282
yamlData = make(map[string]interface{}) // Create an empty config
8383
} else if err != nil {
84-
log.Printf("client: error reading yml file: %v\n", err)
85-
panic(err)
84+
log.Printf("client: error reading yml file. generating empty config: %s\n", err.Error())
85+
yamlData = make(map[string]interface{}) // Create an empty config
8686
} else {
87-
// Parse the YAML file into a map
8887
err = yaml.Unmarshal(data, &yamlData)
8988
if err != nil {
90-
log.Printf("client: error unmarshalling yml: %v\n", err)
91-
panic(err)
89+
log.Printf("client: error unmarshalling yml. generating empty config: %s\n", err.Error())
90+
yamlData = make(map[string]interface{})
9291
}
9392
}
9493

0 commit comments

Comments
 (0)