racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
444 stars 93 forks source link

DrRacket Getting Stuck Auto-saving Files #658

Closed shhyou closed 5 months ago

shhyou commented 5 months ago

The following steps trigger a continuous error in DrRacket.

Steps to reproduce:

  1. Open some file, say A/f.rkt
  2. Make sure to enable "save files whenever switching tabs or windows"
  3. Rename the folder A to B.
  4. Edit f.rkt in DrRacket and switch to a different tab.
  5. DrRacket keeps reporting "cannot save file" errors.

Expected behavior: I don't know. Maybe a different error message and bringing up the "Save as..." dialog?

rfindler commented 5 months ago

It looks to me like the right change here is to simply catch and discard any errors that happen while saving due to the tab switch. That is, the diff below. Does this seem right to you?

$  git diff
diff --git a/drracket/drracket/private/unit.rkt b/drracket/drracket/private/unit.rkt
index a41942cc..059ac15a 100644
--- a/drracket/drracket/private/unit.rkt
+++ b/drracket/drracket/private/unit.rkt
@@ -3001,7 +3001,13 @@
         (let/ec k
           (for ([tab (in-list (get-unsaved-candidate-tabs #f))])
             (parameterize ([editor:silent-cancel-on-save-file-out-of-date? #t])
-              (unless (send (send tab get-defs) save-file #f 'same #f)
+              (unless (with-handlers ([exn:fail? (λ (x) #t)])
+                        ;; catch errors during saving and discard them so
+                        ;; that we don't end up in an infinite loop of errors.
+                        ;; when this happens, the autosave will probably also
+                        ;; error, which will give the user some information
+                        ;; about what's going on here.
+                        (send (send tab get-defs) save-file #f 'same #f))
                 (k (void))))))
         (update-tabs-labels))
shhyou commented 5 months ago

That seems good. After the change, no error shows up and the file is not saved until I explicitly press cmd-s or click the save icon.

rfindler commented 5 months ago

Yeah, and you get the nice error message when you try to explicitly save and you do see the diamond in the tab. So hopefully folks won't get too confused.

Thanks!

sorawee commented 5 months ago

Is this fix going to be a part of 8.12?

rfindler commented 5 months ago

This is an old bug and while I feel prettt good about the fix I would feel even better if we have a release cycle. This part of drr is hard to get right.

On Thu, Jan 11, 2024 at 4:07 PM sorawee @.***> wrote:

Is this fix going to be a part of 8.12?

— Reply to this email directly, view it on GitHub https://github.com/racket/drracket/issues/658#issuecomment-1888045433, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADBNMGH6KBSKXJBIGBXJVDYOBPCXAVCNFSM6AAAAABBWRKFYOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBYGA2DKNBTGM . You are receiving this because you modified the open/close state.Message ID: @.***>

shhyou commented 5 months ago

To be fair, continuing users probably won't exercise that code path for otherwise this bug would have been reported. I noticed this when interacting with new DrRacket users.