{"record":{"id":"6eebe18a0b054de1","repo":"kopia/kopia","slug":"error-parsing-edited-file","errorCode":null,"errorMessage":"error parsing edited file","messagePattern":"error parsing edited file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/editor/editor.go","lineNumber":45,"sourceCode":"\t\treturn errors.Wrap(err, \"unable to create temp directory\")\n\t}\n\n\ttmpFile := filepath.Join(tmpDir, fname)\n\tdefer os.RemoveAll(tmpDir) //nolint:errcheck\n\n\t//nolint:mnd\n\tif err := os.WriteFile(tmpFile, []byte(initial), 0o600); err != nil {\n\t\treturn errors.Wrap(err, \"unable to write file to edit\")\n\t}\n\n\tfor {\n\t\tif err := EditFile(ctx, tmpFile); err != nil {\n\t\t\treturn errors.Wrap(err, \"error launching editor\")\n\t\t}\n\n\t\ttxt, err := readAndStripComments(tmpFile, withComments)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"error parsing edited file\")\n\t\t}\n\n\t\terr = parse(txt)\n\t\tif err == nil {\n\t\t\treturn nil\n\t\t}\n\n\t\tlog(ctx).Errorf(\"%v\", err)\n\t\tfmt.Print(\"Reopen editor to fix? (Y/n) \")\n\n\t\tvar shouldReopen string\n\n\t\t_, _ = fmt.Scanf(\"%s\", &shouldReopen)\n\n\t\tif strings.HasPrefix(strings.ToLower(shouldReopen), \"n\") {\n\t\t\treturn errors.New(\"aborted\")\n\t\t}\n\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/internal/editor/editor.go#L27-L63","documentation":"After each editor run, EditLoop calls readAndStripComments to re-read the temp file and strip '#' comment lines. This error wraps failures reading that file (see also errors 875/876 which wrap the same call's inner errors before reaching here). It signals the edited file could not be opened or read back.","triggerScenarios":"readAndStripComments(tmpFile, withComments) returns an error inside EditLoop — file missing (deleted by editor or tmp cleaner) or unreadable at read-back time.","commonSituations":"A wrapper EDITOR command moves/renames the file instead of editing in place; a tmp cleaner deletes the temp dir during a long editing session; filesystem errors on read.","solutions":["Configure an editor that edits the file in place rather than replacing/renaming it.","Exclude kopia temp paths from background tmp-cleaners.","Retry the command; if reproducible, inspect the wrapped cause for the underlying read/open error."],"exampleFix":"// before\nexport EDITOR=\"my-script\"  # script writes result to a new file path\n// after\nexport EDITOR=\"my-script\"  # script must edit $1 in place","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(tmpFile); err != nil || fi.Size() == 0 {\n    // file vanished before read-back; re-run the edit loop\n}","typeGuard":null,"tryCatchPattern":"if err := editor.EditLoop(ctx, fname, initial, false, parse); err != nil {\n    if errors.Is(err, fs.ErrNotExist) { return errors.New(\"edited file was deleted; check your editor/wrapper\") }\n    return err\n}","preventionTips":["Use editors that save in place at the same path","Don't wrap EDITOR in scripts that move or delete the target file","Keep tmp cleaners away from files modified within the last hour","Retry the edit session after a transient read failure"],"tags":["filesystem","read","editor","temp-file"],"backgroundTag":"file-read-failed","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"}