# Unexpected return (LocalJumpError) when forking off a rake process

**URL:** <https://www.ruby-forum.com/t/unexpected-return-localjumperror-when-forking-off-a-rake-process/122121>\
**Category:** Ruby\
**Created:** [December 4, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/unexpected-return-localjumperror-when-forking-off-a-rake-process/122121 "2007-12-04T19:40:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hans\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ee59a6/32.png) [@Hans\_S](https://www.ruby-forum.com/u/Hans_S)\
**Post date:** [December 4, 2007, 7:40pm UTC](https://www.ruby-forum.com/t/unexpected-return-localjumperror-when-forking-off-a-rake-process/122121/1 "2007-12-04T19:40:51Z")

</div>

I’ve written a small ruby cgi script which allows me to fork off a  
rake process, which in turn forks off other processes interfacing with  
subversion and ant mostly.

I have a long running rakefile and after a few minutes, it bails out  
with the following error message:  
./rake:28: unexpected return (LocalJumpError)  
from ./rake:21:in `chdir’  
from ./rake:21#!/usr/bin/ruby

Anyone got any ideas on what could cause this?

The actual cgi script follows:

require ‘cgi’

cgi = CGI.new

unless cgi.has\_key? ‘rakefile’ then  
cgi.out(‘text/plain’) {‘error: rakefile parameter not set’}  
return  
end

BUILD\_ROOT = ‘/opt/build/builds/’ + cgi[‘rakefile’]  
target = cgi.has\_key?(‘target’) ? cgi[‘target’] : ‘default’

unless File.exists? BUILD\_ROOT then  
cgi.out(‘text/plain’) {‘error: rakefile ’ + cgi[‘rakefile’] + ’ not  
found’}  
return  
end

log = nil

Dir.chdir BUILD\_ROOT do  
begin  
results = `rake #{target} 2>&1`  
log = results  
raise RuntimeError.new(log.chomp!) unless $?.success?  
rescue =\> x  
cgi.out(‘text/plain’) {'error: ’ + x + “\n” + log }  
return  
end  
end

cgi.out(‘text/plain’) {'done: ’ + cgi[‘rakefile’] + “\n” + log}

---

<div class="post-metadata">

**Author:** ![Hans\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ee59a6/32.png) [@Hans\_S](https://www.ruby-forum.com/u/Hans_S)\
**Post date:** [December 4, 2007, 8:12pm UTC](https://www.ruby-forum.com/t/unexpected-return-localjumperror-when-forking-off-a-rake-process/122121/2 "2007-12-04T20:12:00Z")

</div>

On Dec 4, 7:37 pm, Hans S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve written a small ruby cgi script which allows me to fork off a  
> rake process, which in turn forks off other processes interfacing with  
> subversion and ant mostly.

As an addendum, the versions of what I’m using:  
ruby 1.8.5 (2006-08-25) [x86\_64-linux]  
rake, version 0.7.1

---

<div class="post-metadata">

**Author:** ![Hans\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ee59a6/32.png) [@Hans\_S](https://www.ruby-forum.com/u/Hans_S)\
**Post date:** [December 4, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/unexpected-return-localjumperror-when-forking-off-a-rake-process/122121/3 "2007-12-04T20:28:24Z")

</div>

Alle martedì 4 dicembre 2007, Hans S. ha scritto:

> Anyone got any ideas on what could cause this?  
> return
> 
> end  
> end
> 
> cgi.out(‘text/plain’) {'done: ’ + cgi[‘rakefile’] + “\n” + log}
> 
> –  
> Hans

I think this is not related to rake. The problem is that you are using  
return  
when you’re not in a method body, which is (I think) the only place  
return  
can be used. Looking at your code, I think you’re using return to  
terminate  
execution after displaying an error message. In this case, you should  
use the  
Kernel.exit method, instead.

I hope this helps

Stefano
