{"record":{"id":"4a4596ec7980d957","repo":"hyperledger/fabric","slug":"error-returned-from-build-d-s","errorCode":null,"errorMessage":"Error returned from build: %d \"%s\"","messagePattern":"Error returned from build: (.+?) \"(.+?)\"","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/platforms/util/utils.go","lineNumber":158,"sourceCode":"\n\t// -----------------------------------------------------------------------------------\n\t// Wait for the build to complete and gather the return value\n\t// -----------------------------------------------------------------------------------\n\tresWait := client.ContainerWait(context.Background(), container.ID, dcli.ContainerWaitOptions{})\n\tvar res dcontainer.WaitResponse\n\tselect {\n\tcase res = <-resWait.Result:\n\tcase err = <-resWait.Error:\n\t\tcw.Close()\n\t\treturn fmt.Errorf(\"Error waiting for container to complete: %s\", err)\n\t}\n\n\t// Wait for stream copying to complete before accessing stdout.\n\tdefer cw.Close()\n\tbuff, _ := io.ReadAll(cw.Reader)\n\tif res.StatusCode > 0 {\n\t\tlogger.Errorf(\"Docker build failed using options: %s\", opts)\n\t\treturn fmt.Errorf(\"Error returned from build: %d \\\"%s\\\"\", res.StatusCode, string(buff))\n\t}\n\n\tlogger.Debugf(\"Build output is %s\", string(buff))\n\n\t// -----------------------------------------------------------------------------------\n\t// Finally, download the result\n\t// -----------------------------------------------------------------------------------\n\tresCont, err := client.CopyFromContainer(context.Background(), container.ID, dcli.CopyFromContainerOptions{SourcePath: \"/chaincode/output/.\"})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Error downloading output: %s\", err)\n\t}\n\tdefer resCont.Content.Close()\n\tio.Copy(opts.OutputStream, resCont.Content)\n\n\treturn nil\n}\n\n// ParamsImage returns the go, os version and architecture of the ccenv image","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/platforms/util/utils.go#L140-L176","documentation":"The builder container ran to completion but exited with a non-zero status code, meaning the build command (opts.Cmd) failed. DockerBuild logs the failing options at error level and returns the exit code together with the container's captured stdout/stderr output, which typically contains the compiler/toolchain error. This is the normal, expected failure path for a genuine compilation error in the chaincode source or its build command.","triggerScenarios":"res.StatusCode > 0 after ContainerWait returns: the command wrapped as ['/bin/sh','-c',opts.Cmd] exits non-zero — compile errors in the chaincode source, missing dependencies, vendoring problems, unsupported toolchain flags, or a failing script inside the builder image.","commonSituations":"Chaincode Go code that does not compile (syntax or type errors); missing go.mod dependencies or private modules unreachable from the builder; GOFLAGS/GOCACHE issues inside the container; Node.js chaincode failing npm install; users upgrading Fabric where the ccenv toolchain version no longer matches the chaincode code.","solutions":["Read the quoted build output in the error message — it contains the actual compiler error from inside the container","Fix the chaincode source: resolve compile errors, ensure go.mod/go.sum are complete (go mod tidy) and dependencies are vendored or fetchable","Verify the build command (opts.Cmd) and any Env (GOPROXY, GONOSUMDB, GOFLAGS) match the toolchain in the builder image","Rebuild with a matching/current builder image (e.g. hyperledger/fabric-ccenv aligned with your Fabric version) if toolchain version mismatch is the cause"],"exampleFix":"// before: incomplete go.mod causing compile failure in builder\nrequire github.com/hyperledger/fabric-contract-api-go\n// after: generate complete module metadata before building\n// run: go mod tidy && go mod vendor\nrequire github.com/hyperledger/fabric-contract-api-go v1.2.2","handlingStrategy":"try-catch","validationCode":"// Validate chaincode package contents before invoking DockerBuild\nif len(packageTarball) == 0 { return errors.New(\"empty chaincode package\") }\n// for Go: pre-check that source compiles locally\n// cmd := exec.Command(\"go\", \"build\", \"./...\"); run inside the package dir","typeGuard":null,"tryCatchPattern":"if err := util.DockerBuild(opts, client); err != nil {\n    var ec int\n    if _, perr := fmt.Sscanf(err.Error(), \"Error returned from build: %d\", &ec); perr == nil {\n        // surface the quoted build output to the user: real compiler error\n        return fmt.Errorf(\"chaincode compile failed (exit %d): %w\", ec, err)\n    }\n    return err\n}","preventionTips":["Run go mod tidy / vendor dependencies before packaging chaincode","Compile chaincode locally with the same toolchain version as the ccenv image","Keep the builder image version matched to your Fabric release","Include Env settings (GOPROXY etc.) so modules can be fetched inside the container"],"tags":["docker","compile-error","exit-code","chaincode-build","go"],"backgroundTag":"build-exit-code-nonzero","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}