Skip to content

Commit ca04c80

Browse files
committed
fix: result.Ok to keep debugpy from converting Ok to Err
This is a strange bug in debugpy that randomly changes an Ok variant to an Err variant. What happens is in the background the python debugger evaluates all class properties. But evaluating result.Err for an Ok(value) converts it to an Err(e) and returns itself (since it resulted in an error). This leads to random changing of Ok(value) variables by the debugger, that would then work perfectly fine under normal execution. This fix for changes both the Ok and Err properties to return a new instance of an Err(e) if they result in an error and DOES NOT alter self.
1 parent c8813f0 commit ca04c80

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

ResultContainer/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,10 +1087,14 @@ def Ok(self):
10871087
Returns:
10881088
value stored in Ok(value) or raise ResultErr
10891089
"""
1090-
if self._success:
1091-
return self._val
1092-
self.add_Err_msg("Result.Ok attribute for Err variant", 15, add_traceback=True) # 15: "not_Ok",
1093-
raise self._val
1090+
if not self._success:
1091+
# Result.Ok raises error for Err variant
1092+
# Have to operate on new instance for debugpy, otherwise the Locals inspection will convert self to Err.
1093+
# old method: self.add_Err_msg("Result.Ok attribute for Err variant", 15)
1094+
err = ResultErr(self._val)
1095+
err.append("Result.Ok attribute for Err variant", 15, add_traceback=True) # 15: "not_Ok",
1096+
raise err
1097+
return self._val
10941098

10951099
@property
10961100
def Err(self):

0 commit comments

Comments
 (0)