Skip to content

Commit

Permalink
panic when load env failed
Browse files Browse the repository at this point in the history
  • Loading branch information
cpunion committed Nov 20, 2024
1 parent 1e0e754 commit 68f90fd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ var ProjectRoot string

func init() {
if ProjectRoot == "" {
fmt.Fprintf(os.Stderr, "ProjectRoot is not set\n")
return
panic("ProjectRoot is not set, compile with -ldflags '-X github.com/cpunion/go-python.ProjectRoot=/path/to/project/.deps'")
}
envs, err := env.ReadEnv(ProjectRoot)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to read env: %s\n", err)
return
panic(fmt.Sprintf("Failed to read env: %s", err))
}
for key, value := range envs {
os.Setenv(key, value)
Expand Down
2 changes: 1 addition & 1 deletion internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func ReadEnvFile(projectDir string) (map[string]string, error) {
envFile := GetEnvConfigPath(projectDir)
content, err := os.ReadFile(envFile)
if err != nil {
return nil, fmt.Errorf("failed to read env file: %v", err)
return nil, fmt.Errorf("failed to read env file %s: %v", envFile, err)
}
envs := map[string]string{}
for _, line := range strings.Split(strings.TrimSpace(string(content)), "\n") {
Expand Down

0 comments on commit 68f90fd

Please sign in to comment.