Skip to content

Commit 68f90fd

Browse files
committed
panic when load env failed
1 parent 1e0e754 commit 68f90fd

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

inject.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ var ProjectRoot string
1111

1212
func init() {
1313
if ProjectRoot == "" {
14-
fmt.Fprintf(os.Stderr, "ProjectRoot is not set\n")
15-
return
14+
panic("ProjectRoot is not set, compile with -ldflags '-X github.com/cpunion/go-python.ProjectRoot=/path/to/project/.deps'")
1615
}
1716
envs, err := env.ReadEnv(ProjectRoot)
1817
if err != nil {
19-
fmt.Fprintf(os.Stderr, "Failed to read env: %s\n", err)
20-
return
18+
panic(fmt.Sprintf("Failed to read env: %s", err))
2119
}
2220
for key, value := range envs {
2321
os.Setenv(key, value)

internal/env/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func ReadEnvFile(projectDir string) (map[string]string, error) {
133133
envFile := GetEnvConfigPath(projectDir)
134134
content, err := os.ReadFile(envFile)
135135
if err != nil {
136-
return nil, fmt.Errorf("failed to read env file: %v", err)
136+
return nil, fmt.Errorf("failed to read env file %s: %v", envFile, err)
137137
}
138138
envs := map[string]string{}
139139
for _, line := range strings.Split(strings.TrimSpace(string(content)), "\n") {

0 commit comments

Comments
 (0)