1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

fix: Print dotenv file path when there is an error reading file (#1842)

This commit is contained in:
Paulo Bittencourt
2024-09-29 16:03:48 -04:00
committed by GitHub
parent e619bad4a9
commit 8d0f0b049c
4 changed files with 24 additions and 1 deletions

View File

@@ -1657,6 +1657,18 @@ func TestDotenvHasEnvVarInPath(t *testing.T) {
tt.Run(t) tt.Run(t)
} }
func TestTaskDotenvParseErrorMessage(t *testing.T) {
e := task.Executor{
Dir: "testdata/dotenv/parse_error",
}
path, _ := filepath.Abs(filepath.Join(e.Dir, ".env-with-error"))
expected := fmt.Sprintf("error reading env file %s:", path)
err := e.Setup()
require.ErrorContains(t, err, expected)
}
func TestTaskDotenv(t *testing.T) { func TestTaskDotenv(t *testing.T) {
tt := fileContentTest{ tt := fileContentTest{
Dir: "testdata/dotenv_task/default", Dir: "testdata/dotenv_task/default",

View File

@@ -1,6 +1,7 @@
package taskfile package taskfile
import ( import (
"fmt"
"os" "os"
"github.com/joho/godotenv" "github.com/joho/godotenv"
@@ -37,7 +38,7 @@ func Dotenv(c *compiler.Compiler, tf *ast.Taskfile, dir string) (*ast.Vars, erro
envs, err := godotenv.Read(dotEnvPath) envs, err := godotenv.Read(dotEnvPath)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("error reading env file %s: %w", dotEnvPath, err)
} }
for key, value := range envs { for key, value := range envs {
if ok := env.Exists(key); !ok { if ok := env.Exists(key); !ok {

View File

@@ -0,0 +1,2 @@
#intentional parse error
SOME_VAR

View File

@@ -0,0 +1,8 @@
version: '3'
dotenv: ['.env-with-error']
tasks:
default:
cmd: "true"