{"record":{"id":"aa8895a871173be9","repo":"goreleaser/goreleaser","slug":"xz-failed-to-add-s-only-one-file-can-be-archive","errorCode":null,"errorMessage":"xz: failed to add %s, only one file can be archived in xz format","messagePattern":"xz: failed to add (.+?), only one file can be archived in xz format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/archive/xz/xz.go","lineNumber":36,"sourceCode":"}\n\n// New xz archive.\nfunc New(target io.Writer) *Archive {\n\txzw, _ := xz.WriterConfig{DictCap: 16 * 1024 * 1024}.NewWriter(target)\n\treturn &Archive{\n\t\txzw: xzw,\n\t}\n}\n\n// Close all closeables.\nfunc (a *Archive) Close() error {\n\treturn a.xzw.Close()\n}\n\n// Add file to the archive.\nfunc (a *Archive) Add(f config.File) error {\n\tif a.name != \"\" {\n\t\treturn fmt.Errorf(\"xz: failed to add %s, only one file can be archived in xz format\", f.Destination)\n\t}\n\n\tfile, err := os.Open(f.Source) // #nosec\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer file.Close()\n\n\tinfo, err := file.Stat()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif info.IsDir() {\n\t\treturn nil\n\t}\n\n\ta.name = f.Destination","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/goreleaser/goreleaser/blob/f5edd7395693c0c6b501dc722d445d2e86af854d/pkg/archive/xz/xz.go#L18-L54","documentation":"The xz archive format is a single-stream container that holds exactly one file, unlike zip/tar which support multiple entries. Archive.Add tracks the first file added via a.name and refuses any subsequent Add call so it doesn't silently overwrite or corrupt the stream. This is a format limitation enforced explicitly by goreleaser's xz archive implementation.","triggerScenarios":"Calling Archive.Add(f config.File) a second time on the same *xz.Archive instance, i.e. after one successful Add (a.name is non-empty), or when the archive config produces multiple files for an xz-format archive.","commonSituations":"A goreleaser .goreleaser.yaml config where `format: xz` is combined with `files:` listing more than one file (or a glob that expands to several files); devs mistakenly treating xz like tar.gz and adding many files.","solutions":["Change the archive format to tar.xz (format: tar.xz) which supports multiple files, instead of raw xz","Keep only a single file in the `files:` list when using format: xz","Split the archives: use format_overrides or multiple archives entries so each xz archive wraps exactly one file"],"exampleFix":"// before (.goreleaser.yaml)\narchives:\n  - formats: [xz]\n    files: [bin/myapp, LICENSE]\n// after\narchives:\n  - formats: [tar.xz]\n    files: [bin/myapp, LICENSE]","handlingStrategy":"validation","validationCode":"// before creating the xz archive\nif len(files) > 1 {\n    return fmt.Errorf(\"xz format supports only one file; got %d — use tar.xz instead\", len(files))\n}","typeGuard":null,"tryCatchPattern":"// Go: treat as unrecoverable config error\nif err := a.Add(f); err != nil {\n    if strings.Contains(err.Error(), \"only one file can be archived in xz format\") {\n        return fmt.Errorf(\"config error: %w\", err) // do not retry\n    }\n    return err\n}","preventionTips":["Never configure format: xz with more than one file; prefer tar.xz for multi-file archives","Count resolved files (after glob expansion) before adding them to the archive","Add a config validation step in CI (goreleaser check) to catch bad archive configs"],"tags":["go","archive","xz","config"],"backgroundTag":"xz-single-file-limit","analyzedSha":"f5edd7395693c0c6b501dc722d445d2e86af854d","analyzedAt":"2026-09-05T09:57:18.807Z","contentChangedAt":"2026-09-05T09:57:18.807Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}