gohugoio/hugo · critical

workingDir is too short

Error message

workingDir is too short

What it means

A panic in newFs (hugofs/fs.go:110) when the source filesystem is a real OS filesystem and len(workingDir) < 2. The check is skipped for in-memory test filesystems (MemMapFs) but enforced for OsFs to avoid operating relative to a root/empty path.

Source

Thrown at hugofs/fs.go:110

	publishDir := cfg.GetString("publishDirDynamic")
	if publishDir == "" {
		publishDir = cfg.GetString("publishDir")
	}
	return workingDir, publishDir
}

func newFs(source, destination afero.Fs, workingDir, publishDir string) *Fs {
	if publishDir == "" {
		panic("publishDir is empty")
	}

	if workingDir == "." {
		workingDir = ""
	}

	// Sanity check
	if IsOsFs(source) && len(workingDir) < 2 {
		panic("workingDir is too short")
	}

	// If this does not exist, it will be created later.
	absPublishDir := paths.AbsPathify(workingDir, publishDir)

	pubFs := NewBasePathFs(destination, absPublishDir)

	return &Fs{
		Source:             source,
		PublishDir:         pubFs,
		PublishDirServer:   pubFs,
		PublishDirStatic:   pubFs,
		Os:                 &afero.OsFs{},
		WorkingDirReadOnly: getWorkingDirFsReadOnly(source, workingDir),
		WorkingDirWritable: getWorkingDirFsWritable(source, workingDir),
	}
}

View on GitHub (pinned to 52c9bd7908)

Solutions

  1. Run Hugo from a real project directory
  2. Set workingDir to the project root as an absolute path of length >= 2
  3. For tests, use an in-memory afero filesystem which skips this check
Defensive patterns

Strategy: validation

Validate before calling

if hugofs.IsOsFs(source) && len(workingDir) < 2 {
    return nil, errors.New("workingDir too short for an OS filesystem")
}

Prevention

When it happens

Trigger: Running Hugo against the OS filesystem with an empty or root working directory; calling NewDefault/NewFromOld with a config whose workingDir is '' (and not '.').

Common situations: CI or scripts that run from '/' or leave workingDir unset; a misconfigured -s/--source flag resolving to a single character.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/ecaa3b2019badb15. Report an issue: GitHub.