On panic, backup modified buffers only

This commit is contained in:
Dmytro Maluka
2025-08-02 22:43:43 +02:00
parent 7aa495fd3f
commit e127f08251
2 changed files with 8 additions and 4 deletions

View File

@@ -352,9 +352,11 @@ func main() {
} else {
fmt.Println("Micro encountered an error:", errors.Wrap(err, 2).ErrorStack(), "\nIf you can reproduce this error, please report it at https://github.com/zyedidia/micro/issues")
}
// backup all open buffers
// immediately backup all buffers with unsaved changes
for _, b := range buffer.OpenBuffers {
b.Backup()
if b.Modified() {
b.Backup()
}
}
exit(1)
}

View File

@@ -55,9 +55,11 @@ func startup(args []string) (tcell.SimulationScreen, error) {
if err := recover(); err != nil {
screen.Screen.Fini()
fmt.Println("Micro encountered an error:", err)
// backup all open buffers
// immediately backup all buffers with unsaved changes
for _, b := range buffer.OpenBuffers {
b.Backup()
if b.Modified() {
b.Backup()
}
}
// Print the stack trace too
log.Fatalf(errors.Wrap(err, 2).ErrorStack())