hyperledger/fabric · error
no source files found in '%s'
Error message
no source files found in '%s'
What it means
Thrown by WriteFolderToTarPackage when filepath.Walk completed without any file being added to the tar package (the `success` flag was never set). This means the source directory contained no files matching the include/exclude filters, so the resulting package would be empty.
Source
Thrown at core/chaincode/platforms/util/writer.go:101
packagepath = path.Join("src", packagepath)
}
err = WriteFileToPackage(localpath, packagepath, tw)
if err != nil {
return fmt.Errorf("Error writing file to package: %s", err)
}
success = true
return nil
}
if err := filepath.Walk(rootDirectory, walkFn); err != nil {
logger.Infof("Error walking rootDirectory: %s", err)
return err
}
if !success {
return errors.Errorf("no source files found in '%s'", srcPath)
}
return nil
}
// WriteFileToPackage writes a file to a tar stream.
func WriteFileToPackage(localpath string, packagepath string, tw *tar.Writer) error {
logger.Debug("Writing file to tarball:", packagepath)
fd, err := os.Open(localpath)
if err != nil {
return fmt.Errorf("%s: %s", localpath, err)
}
defer fd.Close()
fi, err := fd.Stat()
if err != nil {
return fmt.Errorf("%s: %s", localpath, err)
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Verify srcPath points to the directory that actually contains chaincode source files
- Check includeFileTypeMap/excludeFileTypeMap filters do not exclude every file extension
- Ensure source files are not located inside directories listed in excludeDirs
- List the directory contents (ls -laR) to confirm there are matching files
Example fix
// before: wrong path / overly strict filter
err := util.WriteFolderToTarPackage(tw, "/empty-or-wrong-dir", nil, map[string]bool{".go": true}, nil)
// after: correct path with appropriate filters
err := util.WriteFolderToTarPackage(tw, "/path/to/chaincode", []string{".git"}, nil, nil) Defensive patterns
Strategy: validation
Validate before calling
// verify the source folder contains at least one candidate file before packaging
hasFile := false
filepath.Walk(srcPath, func(p string, info os.FileInfo, err error) error {
if err == nil && !info.IsDir() && !strings.HasPrefix(info.Name(), ".") {
hasFile = true
}
return nil
})
if !hasFile {
return fmt.Errorf("%s contains no files to package", srcPath)
} Prevention
- Always confirm srcPath points at the directory directly containing chaincode sources
- Keep include/exclude extension maps permissive enough to match your source files
- Do not place all sources inside excluded directories
- Run ls on the path (or a CI check) before packaging
When it happens
Trigger: srcPath points to an empty directory; every file's extension is excluded by excludeFileTypeMap or not in includeFileTypeMap (e.g. passing a non-nil includeFileTypeMap that matches no extensions); all files reside only in excluded directories (.git plus excludeDirs); the directory contains only hidden or metadata files that get skipped.
Common situations: Pointing the packager at the wrong path (parent directory instead of the chaincode folder); building a Node.js chaincode whose source is in a subfolder; overly restrictive includeFileTypeMap; chaincode repo where all code lives inside an excluded dir.
Related errors
- Error writing %s to tar: %s
- Error writing file to package: %s
- error writing package metadata to tar
- error writing package code bytes to tar
- failed to create tar for chaincode
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/253df1b2ef2f5c24.
Report an issue: GitHub.