{"record":{"id":"9840b00bd9889ef7","repo":"kopia/kopia","slug":"canceled-when-copying-data","errorCode":null,"errorMessage":"canceled when copying data","messagePattern":"canceled when copying data","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"snapshot/upload/upload.go","lineNumber":401,"sourceCode":"\n\tde.FileSize = written\n\tstreamSize = written\n\n\tatomic.AddInt32(&u.stats.TotalFileCount, 1)\n\tatomic.AddInt64(&u.stats.TotalFileSize, de.FileSize)\n\n\treturn de, nil\n}\n\nfunc (u *Uploader) copyWithProgress(dst io.Writer, src io.Reader) (int64, error) {\n\tuploadBuf := iocopy.GetBuffer()\n\tdefer iocopy.ReleaseBuffer(uploadBuf)\n\n\tvar written int64\n\n\tfor {\n\t\tif u.IsCanceled() {\n\t\t\treturn 0, errors.Wrap(errCanceled, \"canceled when copying data\")\n\t\t}\n\n\t\treadBytes, readErr := src.Read(uploadBuf)\n\n\t\tif readBytes > 0 {\n\t\t\twroteBytes, writeErr := dst.Write(uploadBuf[0:readBytes])\n\t\t\tif wroteBytes > 0 {\n\t\t\t\twritten += int64(wroteBytes)\n\t\t\t\tu.totalWrittenBytes.Add(int64(wroteBytes))\n\t\t\t\tu.Progress.HashedBytes(int64(wroteBytes))\n\t\t\t}\n\n\t\t\tif writeErr != nil {\n\t\t\t\t//nolint:wrapcheck\n\t\t\t\treturn written, writeErr\n\t\t\t}\n\n\t\t\tif readBytes != wroteBytes {","sourceCodeStart":383,"sourceCodeEnd":419,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/snapshot/upload/upload.go#L383-L419","documentation":"Cancellation guard in Uploader.copyWithProgress: u.IsCanceled() became true mid-copy (user interrupt, shutdown, or policy cancellation), so the upload loop stops immediately and reports errCanceled wrapped as 'canceled when copying data' instead of continuing a partial upload.","triggerScenarios":"Thrown at snapshot/upload/upload.go:401 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Detect cancellation with errors.Is on the canceled sentinel and re-run the snapshot when appropriate."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}