Skip to content

Commit 6604b9a

Browse files
authored
fix: special variable type errors in vars with no task context (#2107)
* fix: stop dotenv trying to fetch variables when no dotenv specified * fix: set special variables to "" when they can't be calculated
1 parent 6ee1053 commit 6604b9a

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

compiler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,16 @@ func (c *Compiler) getSpecialVars(t *ast.Task, call *Call) (map[string]string, e
209209
allVars["TASK_DIR"] = filepathext.SmartJoin(c.Dir, t.Dir)
210210
allVars["TASKFILE"] = t.Location.Taskfile
211211
allVars["TASKFILE_DIR"] = filepath.Dir(t.Location.Taskfile)
212+
} else {
213+
allVars["TASK"] = ""
214+
allVars["TASK_DIR"] = ""
215+
allVars["TASKFILE"] = ""
216+
allVars["TASKFILE_DIR"] = ""
212217
}
213218
if call != nil {
214219
allVars["ALIAS"] = call.Task
220+
} else {
221+
allVars["ALIAS"] = ""
215222
}
216223

217224
return allVars, nil

setup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ func (e *Executor) setupCompiler() error {
209209
}
210210

211211
func (e *Executor) readDotEnvFiles() error {
212+
if e.Taskfile == nil || len(e.Taskfile.Dotenv) == 0 {
213+
return nil
214+
}
215+
212216
if e.Taskfile.Version.LessThan(ast.V3) {
213217
return nil
214218
}

taskfile/dotenv.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ import (
1212
)
1313

1414
func Dotenv(vars *ast.Vars, tf *ast.Taskfile, dir string) (*ast.Vars, error) {
15-
if len(tf.Dotenv) == 0 {
16-
return nil, nil
17-
}
18-
1915
env := ast.NewVars()
2016
cache := &templater.Cache{Vars: vars}
2117

0 commit comments

Comments
 (0)