The behavior you've observed suggests that there was an issue with how ok_or and ok_or_else were being used or perceived. Understanding the distinction between these two methods and their execution timing can clarify why switching to ok_or_else resolved the issue.
ok_or vs. ok_or_else
ok_or: This method is eager, meaning the error argument is evaluated immediately, regardless of whether it's needed. This means the error block code executes every time ok_or is called, and only after this execution does it check whether to use the evaluated error or the value from the Option.
ok_or_else: This method is lazy and only evaluates the error block when needed, i.e., when the Option is None. This prevents unnecessary computation or side effects if the Option is actually Some(value).
Fix was a simple change from
ok_or
took_or_else
.As per ChatGPT: