Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example code for andthen docs occasionally returns error: Attempt to return outside of any Routine #4398

Open
jubilatious1 opened this issue Nov 10, 2023 · 3 comments

Comments

@jubilatious1
Copy link
Collaborator

jubilatious1 commented Nov 10, 2023

Example code for andthen docs occasionally returns error: Attempt to return outside of any Routine

https://docs.raku.org/routine/andthen

sub load-data {
    rand  > .5 or return; # simulated load data failure; return Nil 
    (rand > .3 ?? 'error' !! 'good data') xx 10 # our loaded data 
}
load-data.first: /good/ andthen say "$_ is good"; # OUTPUT: «(good data is good)␤» 
 
load-data() andthen .return; # return loaded data, if it's defined 
die "Failed to load data!!";

Returns (sample):

===11/10/23 11:55:27===
Use of Nil in string context
  in block <unit> at - line 5
Failed to load data!!
  in block <unit> at - line 8

===11/10/23 11:55:32===
good data is good
Failed to load data!!
  in block <unit> at - line 8

===11/10/23 11:55:38===
Use of Nil in string context
  in block <unit> at - line 5
Attempt to return outside of any Routine
  in block <unit> at - line 7

The Attempt to return outside of any Routine error above seems to distract from the main point of the code.

@raiph
Copy link
Contributor

raiph commented Nov 11, 2023

The example is nonsense. An attempt to return outside of any Routine is always a runtime exception.

@jubilatious1
Copy link
Collaborator Author

@raiph , not a great way to treat new users--filling the andthen Docs with nonsense code instead of something they can actually learn from.

@2colours
Copy link
Contributor

I'm thinking what to do about it. I don't really like the whole example (and I also don't like the last paragraph).

The banal fix would be to wrap the whole snippet into a function like analyze-and-load... but that wouldn't improve the convoluted nature of the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants