{"record":{"id":"21a35f2a59f913e3","repo":"grafana/k6","slug":"serialising-archive-w","errorCode":null,"errorMessage":"serialising archive: %w","messagePattern":"serialising archive: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/provisioning/provision.go","lineNumber":72,"sourceCode":"// provisioning flow: CreateOrFindLoadTest → StartLocalExecution →\n// optional UploadArchive → WaitForTestRunReady.\nfunc (c *Client) ProvisionLocalExecution(ctx context.Context, params ProvisionParams) (*ProvisionResult, error) {\n\tloadTestID, err := c.v6Client.CreateOrFindLoadTest(ctx, params.ProjectID, params.Name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"create or find load test: %w\", err)\n\t}\n\n\t// Serialise archive once to get its byte-length for the\n\t// start_local_execution body. The same buffer is reused for\n\t// the S3 upload to avoid a second serialisation.\n\tvar (\n\t\tarchiveSize  int64\n\t\tarchiveBytes []byte\n\t)\n\tif params.Archive != nil {\n\t\tvar buf bytes.Buffer\n\t\tif err := params.Archive.Write(&buf); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"serialising archive: %w\", err)\n\t\t}\n\t\tarchiveSize = int64(buf.Len())\n\t\tarchiveBytes = buf.Bytes()\n\t}\n\n\tsleReq := StartLocalExecutionRequest{\n\t\tOptions:       params.Options,\n\t\tMaxVUs:        params.MaxVUs,\n\t\tTotalDuration: params.TotalDuration,\n\t\tArchiveSize:   archiveSize,\n\t}\n\n\tsleResp, err := c.StartLocalExecution(ctx, loadTestID, sleReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"start local execution: %w\", err)\n\t}\n\n\tswitch {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cloudapi/provisioning/provision.go#L54-L90","documentation":"ProvisionLocalExecution could not serialize the test archive: params.Archive.Write(&buf) failed while producing the tar bytes whose length is needed for the start_local_execution request and whose bytes are later uploaded to S3. The wrapped error comes from lib.Archive's writer and usually indicates a problem with the archive contents (script sources, embedded files), not with the network or cloud API.","triggerScenarios":"Passing a hand-constructed or corrupted *lib.Archive, a script whose source references unreadable/missing files, filesystem errors while reading referenced assets during Write, or an archive built by a mismatched k6 version with an incompatible internal layout.","commonSituations":"Programmatically building an Archive (xk6/extensions) instead of loading it from disk, moving an archive between machines where referenced file paths no longer resolve, or a partially-written archive from a previous failed `k6 archive` run.","solutions":["Validate the archive independently first: run `k6 archive script.js` and confirm it succeeds","If constructing the Archive in code, prefer lib.ReadArchive(bytes.NewReader(archiveBytes)) over assembling fields manually","Check that all files referenced by the script (open() calls, data files) exist and are readable","Update both producer and consumer to the same k6 version if the archive came from another binary"],"exampleFix":"// before\nres, err := client.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{Archive: handBuiltArchive})\n\n// after\narc, err := lib.ReadArchive(bytes.NewReader(archiveBytes))\nif err != nil { return fmt.Errorf(\"reading archive: %w\", err) }\nres, err := client.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{Archive: arc})","handlingStrategy":"try-catch","validationCode":"// validate the archive round-trips before provisioning\nvar buf bytes.Buffer\nif err := arc.Write(&buf); err != nil {\n    return fmt.Errorf(\"archive is not serializable: %w\", err)\n}\nif buf.Len() == 0 {\n    return fmt.Errorf(\"archive serialized to 0 bytes; refusing to provision\")\n}","typeGuard":null,"tryCatchPattern":"if err := params.Archive.Write(&buf); err != nil {\n    return nil, fmt.Errorf(\"serialising archive: %w\", err)\n}\n// fall back to re-reading from disk if the in-memory archive is broken\nif params.ArchivePath != \"\" {\n    if f, ferr := os.Open(params.ArchivePath); ferr == nil {\n        defer f.Close()\n        buf.Reset()\n        _ = params.Archive.Write(&buf) // try again from the on-disk copy\n    }\n}","preventionTips":["Run `k6 archive script.js` in CI as a pre-flight check before any cloud provisioning","Construct archives via lib.ReadArchive instead of manual struct assembly","Keep k6 versions aligned between archive producer and the binary that uploads it"],"tags":["archive","serialization","provisioning","filesystem"],"backgroundTag":"serialization-failed","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}