{"record":{"id":"6b06920ecfda9e07","repo":"yorukot/superfile","slug":"cannot-spawn-process-w","errorCode":null,"errorMessage":"cannot spawn process : %w","messagePattern":"cannot spawn process : %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations_compress.go","lineNumber":91,"sourceCode":"\t\ttotalFiles, err := validateCompressOperation(filesToCompress)\n\t\tif err != nil {\n\t\t\treturn NewNotifyModalMsg(notify.New(true, \"Invalid file/dir to compress\", err.Error(), notify.NoAction),\n\t\t\t\treqID)\n\t\t}\n\t\tif err := zipSources(filesToCompress, totalFiles, zipPath, &m.processBarModel); err != nil {\n\t\t\tslog.Error(\"Error in zipping files\", \"error\", err)\n\t\t\treturn NewCompressOperationMsg(processbar.Failed, reqID)\n\t\t}\n\t\treturn NewCompressOperationMsg(processbar.Successful, reqID)\n\t}\n}\n\nfunc zipSources(sources []string, totalFiles int, target string, processBar *processbar.Model) error {\n\tvar err error\n\n\tp, err := processBar.SendAddProcessMsg(filepath.Base(target), processbar.OpCompress, totalFiles, true)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot spawn process : %w\", err)\n\t}\n\t_, err = os.Stat(target)\n\tif err == nil {\n\t\tp.ErrorMsg = \"File already exists\"\n\t\tp.State = processbar.Cancelled\n\t\tp.DoneTime = time.Now()\n\t\tpSendErr := processBar.SendUpdateProcessMsg(p, true)\n\t\tif pSendErr != nil {\n\t\t\tslog.Error(\"Error sending process update\", \"error\", pSendErr)\n\t\t}\n\t\treturn errors.New(\"file already exists\")\n\t}\n\n\tf, err := os.Create(target)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer f.Close()","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations_compress.go#L73-L109","documentation":"zipSources wraps a failure from processBar.SendAddProcessMsg when it tries to register a new compression process entry in the progress-bar model. The compression never starts because the progress tracking infrastructure could not spawn the process record.","triggerScenarios":"Calling zipSources with a processbar.Model whose message channel is closed/unavailable, the TUI is shutting down, or the internal message send fails (e.g. model not initialized or already terminated).","commonSituations":"Starting a compression while the UI is exiting; reusing a finished/closed processbar.Model; race between UI teardown and a queued compression job.","solutions":["Ensure the processbar.Model is initialized and its event loop is running before calling zipSources.","Check application shutdown ordering: cancel compressions before closing the TUI.","Recover the wrapped cause with errors.Unwrap/errors.As to see the underlying send failure.","Retry the operation with a fresh processbar.Model if the previous one was closed."],"exampleFix":"// before\np, err := processBar.SendAddProcessMsg(filepath.Base(target), processbar.OpCompress, totalFiles, true)\nif err != nil {\n    return fmt.Errorf(\"cannot spawn process : %w\", err)\n}\n// after\nselect {\ncase <-done: // UI shutting down\n    return fmt.Errorf(\"compression cancelled: UI shutting down\")\ndefault:\n}\np, err := processBar.SendAddProcessMsg(filepath.Base(target), processbar.OpCompress, totalFiles, true)\nif err != nil {\n    return fmt.Errorf(\"cannot spawn process : %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// ensure the progress model is alive before starting\nif processBar == nil || shuttingDown {\n    return fmt.Errorf(\"progress UI not available\")\n}","typeGuard":null,"tryCatchPattern":"if err := ops.ZipSources(sources, total, target, processBar); err != nil {\n    if strings.Contains(err.Error(), \"cannot spawn process\") {\n        // recreate processbar.Model and retry, or run without progress UI\n    }\n    return err\n}","preventionTips":["Initialize the processbar.Model before starting compression jobs.","Cancel in-flight compressions during UI shutdown, not after.","Don't reuse a closed/finished processbar.Model instance."],"tags":["go","progress-bar","process-spawn","compress"],"backgroundTag":"process-spawn-failed","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}