twpayne/chezmoi · error

%s: %w

Error message

%s: %w

What it means

In archiveReaderSystem (internal/chezmoi/archivereadersystem.go:63), while walking an archive, entries are stored by kind: directories skipped, regular files read into contents, symlinks recorded as linknames. Any error reading a regular file's contents is wrapped as "%s: %w" with the entry name.

Source

Thrown at internal/chezmoi/archivereadersystem.go:63

			components := name.SplitAll()
			if len(components) <= options.StripComponents {
				return nil
			}
			name = NewRelPathFromComponents(components[options.StripComponents:]...)
		}
		if name.IsEmpty() {
			return nil
		}
		nameAbsPath := options.RootAbsPath.Join(name)

		s.fileInfos[nameAbsPath] = fileInfo
		switch {
		case fileInfo.IsDir():
			// Do nothing.
		case fileInfo.Mode()&fs.ModeType == 0:
			contents, err := io.ReadAll(r)
			if err != nil {
				return fmt.Errorf("%s: %w", name, err)
			}
			s.contents[nameAbsPath] = contents
		case fileInfo.Mode()&fs.ModeType == fs.ModeSymlink:
			s.linkname[nameAbsPath] = linkname
		default:
			return fmt.Errorf("%s: unsupported mode %o", name, fileInfo.Mode()&fs.ModeType)
		}
		return nil
	}); err != nil {
		return nil, err
	}

	return s, nil
}

// FileInfos returns s's fs.FileInfos.
func (s *ArchiveReaderSystem) FileInfos() map[AbsPath]fs.FileInfo {
	return s.fileInfos

View on GitHub (pinned to f901167e46)

Solutions

  1. Re-download or regenerate the archive; verify checksum/size.
  2. Test archive integrity with `gzip -t`, `zstd -t`, or `tar -tf` before use.
  3. If reading from a network source, retry the fetch and check for connection issues.

Example fix

// before
sys.ReadArchive(badReader)
// after
data, err := io.ReadAll(resp.Body)
if err != nil { return err }
sys.ReadArchive(bytes.NewReader(data))
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify archive integrity before reading
if err := verifyChecksum(archivePath); err != nil {
    return fmt.Errorf("archive corrupt: %w", err)
}

Try / catch

if err := sys.ReadArchive(r); err != nil {
    // wrapped "%s: %w" — log entry name, re-fetch archive, retry once
    return fmt.Errorf("archive read failed: %w", err)
}

Prevention

When it happens

Trigger: WalkFile on an archive reader system encounters a regular-file entry whose underlying reader fails mid-read (io.ReadAll error), e.g. truncated or corrupt archive data.

Common situations: Partially downloaded or truncated archive; I/O failure reading from a network stream passed to readArchive; corrupted compressed stream (bad gzip/zstd data).

Related errors


AI-assisted analysis of twpayne/chezmoi@f901167e46 (2026-09-01). Data as JSON: /api/errors/b8f2856c955cea6f. Report an issue: GitHub.