Skip to content

Commit

Permalink
Fix #341: Prevent that errors are hidden during commits
Browse files Browse the repository at this point in the history
The ifRejected: [nil] in actionCommit turned the effective Promise
for the save into one that always gets resolved rather than rejected.

But the promise is also rejected if the user cancels the save dialog.
Now waitFor: will signal either the inner Error (or rather a copy of it)
or the BrokenPromise if it was not rejected with an Error.
  • Loading branch information
j4yk committed Aug 25, 2021
1 parent fb0b227 commit eb8569b
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Squit.package/SquitBrowser.class/instance/actionCommit.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ actionCommit
((workingCopy newInteractiveSaveOperation
title: 'Select changes and message for the new version';
applyToWorkingCopy)
then: [:result | self refresh]
ifRejected: [:reason | nil])]
on: BrokenPromise do: [:e | e ifNotError: []]].
then: [:result | self refresh])]
on: BrokenPromise do: [:e | "cancelled" e return]].
2 changes: 1 addition & 1 deletion src/Squit.package/SquitBrowser.class/methodProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"actionBranchUnsetUpstream" : "jr 7/20/2020 13:02",
"actionBrowseWorkingCopy" : "jr 8/14/2018 10:25",
"actionClearSearch" : "fn 4/11/2017 18:49",
"actionCommit" : "jr 8/9/2020 22:44",
"actionCommit" : "jr 8/25/2021 09:57",
"actionCommitCherryPick" : "jr 8/8/2020 15:53",
"actionCommitDiffWithNextSelected" : "jr 7/2/2017 19:30",
"actionCommitDiffWithParent" : "jr 2/27/2020 01:00",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*Squot-Tools
ifError: errorBlock ifNotError: rejectedBlock
| reason |
reason := self reason.
^ (reason isKindOf: Error)
ifTrue: [errorBlock cull: reason]
ifFalse: [rejectedBlock cull: reason]
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
*Squot-Tools
ifNotError: aBlock
"Workaround for bad Promise implementation up to Squeak 5.3: value of ifRejected: blocks is not used to resolve the then-Promise, but to reject it. Also Promises in Squeak 5.3 do not take on the outcome of nested promises, they just nest the rejected promise as the error reason. Check whether the promise error is a real Error exception or whether it is a custom error reason. If it is a real Error, pass the BrokenPromise on. Otherwise evaluate the block to run business logic."
| nested |
nested := promise.
[(nested isKindOf: Promise) and: [nested isRejected]] whileTrue: [nested := nested error].
(nested isKindOf: Error)
ifTrue: [self pass]
ifFalse: [^ aBlock cull: nested].
^ self ifError: [self pass] ifNotError: [:reason | aBlock cull: reason]
"[Promise new rejectWith: 42; wait]
on: BrokenPromise do: [:e | e ifNotError: []]" "expected: nil"
"[((Promise new rejectWith: 42) then: [:x|] ifRejected: [:x | nil]) wait]
Expand Down
6 changes: 6 additions & 0 deletions src/Squot.package/BrokenPromise.extension/instance/reason.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*Squot-Tools
reason
| nested |
nested := promise.
[(nested isKindOf: Promise) and: [nested isRejected]] whileTrue: [nested := nested error].
^ nested
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
"class" : {
},
"instance" : {
"ifNotError:" : "jr 8/9/2020 23:42" } }
"ifError:ifNotError:" : "jr 8/25/2021 09:49",
"ifNotError:" : "jr 8/25/2021 09:50",
"reason" : "jr 8/25/2021 09:48" } }
4 changes: 3 additions & 1 deletion src/Squot.package/SquotGUI.class/class/waitFor..st
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ waitFor: aWaitable
Project current spawnNewProcess.
"Start another process that waits in the background, then reinstantes oldProcess as UI process. The oldProcess waits until all of this is over. The reason for a third process is that oldProcess must be suspended temporarily before it can be reinstated in Project class>>resumeProcess:."
[[[answer := aWaitable wait]
on: BrokenPromise do:
[:bp | bp ifError: [:error | exception := error. bp return] ifNotError: [bp pass]]
on: Error do:
[:e | exception := e]]
[:e | exception := e. e return]]
ensure:
[| canContinue |
newProcess := Project uiProcess.
Expand Down
2 changes: 1 addition & 1 deletion src/Squot.package/SquotGUI.class/methodProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"requestPassword:" : "jr 7/24/2020 10:04",
"runInUiProcess:" : "jr 7/24/2020 09:59",
"updateProgress:text:" : "jr 9/13/2020 18:23",
"waitFor:" : "jr 5/14/2021 17:16" },
"waitFor:" : "jr 8/25/2021 09:56" },
"instance" : {
} }

0 comments on commit eb8569b

Please sign in to comment.