{"record":{"id":"be6e134476be2d9c","repo":"wavetermdev/waveterm","slug":"failed-to-marshal-backup-metadata-w","errorCode":null,"errorMessage":"failed to marshal backup metadata: %w","messagePattern":"failed to marshal backup metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/filebackup/filebackup.go","lineNumber":76,"sourceCode":"\t}\n\n\tbackupName := fmt.Sprintf(\"%s.%s.%s.bak\", basename, dirHash8, uuidStr)\n\tbackupPath := filepath.Join(backupDir, backupName)\n\n\terr = os.WriteFile(backupPath, fileData, 0600)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to write backup file: %w\", err)\n\t}\n\n\tmetadata := BackupMetadata{\n\t\tFullPath:  absFilePath,\n\t\tTimestamp: now.Format(time.RFC3339),\n\t\tPerm:      fmt.Sprintf(\"%04o\", fileInfo.Mode().Perm()),\n\t}\n\n\tmetadataJSON, err := json.MarshalIndent(metadata, \"\", \"  \")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to marshal backup metadata: %w\", err)\n\t}\n\n\tmetadataName := fmt.Sprintf(\"%s.%s.%s.json\", basename, dirHash8, uuidStr)\n\tmetadataPath := filepath.Join(backupDir, metadataName)\n\n\terr = os.WriteFile(metadataPath, metadataJSON, 0600)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to write backup metadata: %w\", err)\n\t}\n\n\treturn backupPath, nil\n}\n\nfunc RestoreBackup(backupFilePath string, restoreToFileName string) error {\n\tbackupData, err := os.ReadFile(backupFilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read backup file: %w\", err)\n\t}","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/filebackup/filebackup.go#L58-L94","documentation":"MakeFileBackup serializes BackupMetadata (FullPath, Timestamp, Perm) to indented JSON before writing the .json sidecar. This error wraps json.MarshalIndent failing. It is practically unreachable: the struct contains only string fields which cannot fail to marshal, so seeing it indicates an extraordinary encoding/json failure.","triggerScenarios":"json.MarshalIndent(metadata, \"\", \"  \") returns an error — with the fixed BackupMetadata string-only struct this essentially cannot happen; only a broken/patched json package or extreme memory conditions would trigger it.","commonSituations":"Custom builds with modified BackupMetadata containing unsupported types (e.g. channels, funcs, cycles); out-of-memory conditions.","solutions":["Inspect BackupMetadata for any newly added non-serializable fields if the struct was modified.","Check memory availability if running under extreme constraints.","Retry the operation; treat as transient if it cannot be reproduced."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"backupPath, err := filebackup.MakeFileBackup(absPath)\nif err != nil {\n    if strings.Contains(err.Error(), \"marshal backup metadata\") {\n        log.Errorf(\"unexpected metadata marshal failure: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep BackupMetadata limited to JSON-serializable string fields","Don't patch encoding/json or the metadata struct without tests","Treat occurrences as a code bug and report it"],"tags":["json","serialization","backup","go"],"backgroundTag":"json-marshal-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}