Surface .env load errors (#6707)

We drop errors loading from loading `.env` in the past.
This is hard to debug and can cause confusion, so we change it with this.
This commit is contained in:
6543
2026-06-08 10:21:45 +02:00
committed by GitHub
parent cf44ce8f84
commit 2aaf487a39
7 changed files with 37 additions and 5 deletions
+1
View File
@@ -80,6 +80,7 @@
"gocritic",
"GODEBUG",
"godoc",
"godotenv",
"Gogs",
"golangci",
"gomod",
-2
View File
@@ -19,8 +19,6 @@ import (
"os"
"slices"
// Load config from .env file.
_ "github.com/joho/godotenv/autoload"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v3"
+8
View File
@@ -16,7 +16,10 @@ package main
import (
"context"
"fmt"
"os"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
"go.woodpecker-ci.org/woodpecker/v3/cmd/agent/core"
@@ -34,6 +37,11 @@ var backends = []backend_types.Backend{
}
func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
ctx := utils.WithContextSigtermCallback(context.Background(), func() {
log.Info().Msg("termination signal is received, shutting down agent")
})
+7
View File
@@ -18,7 +18,9 @@ package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
docs "github.com/urfave/cli-docs/v3"
"go.woodpecker-ci.org/woodpecker/v3/cmd/agent/core"
@@ -35,6 +37,11 @@ var backends = []backend_types.Backend{
}
func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
app := core.GenApp(backends)
md, err := docs.ToMan(app)
if err != nil {
+7 -1
View File
@@ -16,15 +16,21 @@ package main
import (
"context"
"fmt"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
"go.woodpecker-ci.org/woodpecker/v3/shared/utils"
)
func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
ctx := utils.WithContextSigtermCallback(context.Background(), func() {
log.Info().Msg("termination signal is received, terminate cli")
})
+7 -1
View File
@@ -18,9 +18,10 @@ package main
import (
"context"
"fmt"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
"github.com/rs/zerolog/log"
_ "go.woodpecker-ci.org/woodpecker/v3/cmd/server/openapi"
@@ -28,6 +29,11 @@ import (
)
func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
ctx := utils.WithContextSigtermCallback(context.Background(), func() {
log.Info().Msg("termination signal is received, shutting down server")
})
+7 -1
View File
@@ -18,14 +18,20 @@ package main
import (
"fmt"
"os"
_ "github.com/joho/godotenv/autoload"
"github.com/joho/godotenv"
docs "github.com/urfave/cli-docs/v3"
_ "go.woodpecker-ci.org/woodpecker/v3/cmd/server/openapi"
)
func main() {
if err := godotenv.Load(); err != nil {
fmt.Fprintf(os.Stderr, "Error could not load .env: %s", err)
os.Exit(1)
}
app := genApp()
md, err := docs.ToMan(app)
if err != nil {