hyperledger/fabric · error
failed to unmarshal output from 'go list'
Error message
failed to unmarshal output from 'go list'
What it means
listModuleInfo runs 'go list -m -json' in module mode and json.Unmarshals its output; if the output is not valid JSON matching the expected shape, it wraps the failure with 'failed to unmarshal output from 'go list''. Indicates the go tool produced unexpected output.
Solutions
- Check GOFLAGS and GOENV for settings that make go print extra output; unset them (GOFLAGS=)
- Ensure the builder image's Go version is one supported by the fabric version
- Run 'go list -m -json' manually in the chaincode dir to inspect raw output
- Remove any go wrapper/shim scripts that prepend text to stdout
Example fix
// before GOFLAGS="-mod=vendor -x" (verbose output pollutes) // after GOFLAGS="-mod=vendor"
Defensive patterns
Strategy: validation
Validate before calling
out, err := exec.Command("go", "list", "-m", "-json").Output()
if err != nil { return err }
if !json.Valid(out) { return fmt.Errorf("go list emitted non-JSON output: %s", out) } Prevention
- Unset GOFLAGS that add non-JSON output
- Use a fabric-supported Go version in the builder
- Do not wrap the go binary with scripts writing to stdout
- Set LANG=C to avoid locale-induced output
When it happens
Trigger: moduleInfo -> listModuleInfo: the 'go list' subprocess output cannot be unmarshalled into the anonymous struct {Dir, ImportPath, GoMod, Module{...}} — e.g. go printed warnings/human text to stdout, or an ancient/odd go version emitted different JSON.
Common situations: GOFLAGS injecting extra output; wrapper scripts around go polluting stdout; very old Go toolchain in builder image; locale/encoding output mixed into the stream.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- config isn't valid
- Failed opening file
- too few arguments
- cannot query joinbysnapshot status, due to
- connection.json not found in source folder
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/12448d57f5eb7fec.
Report an issue: GitHub.
Appendix: source
Thrown at core/chaincode/platforms/golang/list.go:133
cmd := exec.CommandContext(ctx, "go", "list", "-json", ".")
cmd.Env = append(os.Environ(), extraEnv...)
output, err := cmd.Output()
if err != nil {
return nil, wrapExitErr(err, "'go list' failed")
}
var moduleData struct {
ImportPath string
Module struct {
Dir string
Path string
GoMod string
}
}
if err := json.Unmarshal(output, &moduleData); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal output from 'go list'")
}
return &ModuleInfo{
Dir: moduleData.Module.Dir,
GoMod: moduleData.Module.GoMod,
ImportPath: moduleData.ImportPath,
ModulePath: moduleData.Module.Path,
}, nil
}
View on GitHub (pinned to 2736b63f8f)