Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4257734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:33:10+00:00 2026-05-21T05:33:10+00:00

How do I pass an error from my Module back to the rake task

  • 0

How do I pass an error from my Module back to the rake task that called it?

My rake task looks like this:

require 'mymodule.rb'

task :queue => :environment do
  OPERATOR = Mymodule::Operator.new
  begin
    OPERATOR.initiate_call (1234567189)
  rescue StandardError => bang
    puts "Shit happened: #{ bang} "
  end   
end

And here is my module..

module Mymodule
  class Operator    
    def initiate_call (number)
      begin
        # make the call
      rescue StandardError => bang
        flash[:error] = "Error #{bang}"
        return
      end
    end    
  end
end

I also call this module from a controller so it would be nice to have an error handling solution that is more or less agnostic.

Running Rails 3. Any unrelated comments (i.e. suggestions) on my code structure are more than welcomed 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:33:12+00:00Added an answer on May 21, 2026 at 5:33 am

    Your Operator#initiate_call method traps StandardError exceptions so your rake task will never see them. I’d drop the rescue from initiate_call and let the caller deal with all the exception handling. Then, you’d have flash[:error] = "Error #{bang}" in your controller’s exception handler and the rake task would remain as-is.

    The basic approach is to push the error handling up the call stack all the way to someone that can do something about it; initiate_call can’t really do anything useful with the exception so it shouldn’t try to handle it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Invalid octal digit error in Ruby, how do I by pass that? I have
This is the code I am working with that comes from Practical Programming: import
I am trying this simple ctypes example and getting the error mentioned >>> from
How can I pass message parameters to an error message when using rejectValue ?
Error in Rails Tutorial (Hartl) v3.2 I'm on chapter 8 and all tests pass
ERROR: unknown web method DoIt Parameter name: methodName I'm trying to pass a date
Can I pass a variable to a SELECT statement? I keep getting an error
If I pass an empty list into a JPA query, I get an error.
I'm calling pipe.communicate from Python's subprocess module from Python 2.6. I get the following
Here is my custom module using hook, Assume if I want to pass argument

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.