concept error in category ruby

This is an excerpt from Manning's book The Well-Grounded Rubyist, Third Edition.
The first call to scanf fails with an error 1. But after the require call 2, and with no further programmer intervention, string objects like "David Black" respond to the scanf message. (In this example 3, we’re asking for two consecutive strings to be extracted from the original string, with whitespace as an implied separator.)
When something goes wrong with file operations, Ruby raises an exception. Most of the errors you’ll get in the course of working with files can be found in the Errno namespace: Errno::EACCES (permission denied), Errno::ENOENT (no such entity—a file or directory), Errno::EISDIR (is a directory—an error you get when you try to open a directory as if it were a file), and others. You’ll always get a message along with the exception:
>> File.open("no_file_with_this_name") Errno::ENOENT (No such file or directory @ rb_sysopen - no_file_with_this_name) >> f = File.open("/tmp") => #<File:/tmp> >> f.gets Errno::EISDIR (Is a directory @io_fillbuff - /tmp) >> File.open("/var/root") Errno::EACCES (Permission denied - /var/root)The Errno family of errors includes not only file-related errors but also other system errors. The underlying system typically maps errors to integers (for example, on Linux, the “not a directory” error is represented by the C macro ENOTDIR, which is defined as the number 20). Ruby’s Errno class wraps these error-to-number mappings in a bundle of exception classes.

This is an excerpt from Manning's book Rails 4 in Action: Revised Edition of Rails 3 in Action.
If you don’t get these answers, or you get some sort of error message, please be sure to complete this setup before you try to move on; you can’t just ignore errors with this process. Certain gems (and Rails itself) only support particular versions of Ruby, so if you don’t get this right, things won’t work.
This error points at line 6 of your app/views/projects/index.html.erb file, which reads <% @projects.each do |project| %>. From this you can determine that the error must have something to do with the @projects variable. This variable hasn’t yet been defined, and as mentioned in chapter 3, instance variables in Ruby return nil rather than raise an exception. So because @projects is nil, and there’s no each method on nil, you get this error, undefined method 'each' for nil:NilClass. Watch out for this in Ruby—as you can see here, it can sting you hard.
Listing 15.14. Adding API request specs for error handling
describe API::V2::Tickets do ... context "unsuccessful requests" do it "doesn't allow requests that don't pass through an API key" do get url expect(response.status).to eq 401 expect(response.body).to include "Unauthenticated" end it "doesn't allow requests that pass an invalid API key" do get url, {}, { "HTTP_AUTHORIZATION" => "Token token=notavalidkey" } expect(response.status).to eql 401 expect(response.body).to include "Unauthenticated" end it "doesn't allow access to a ticket that the user doesn't have permission to read" project.roles.delete_all get url, {}, headers expect(response.status).to eq 404 end end end

This is an excerpt from Manning's book Flexible Rails: Flex 3 on Rails 2.
Once the service returns, the result triggers the handleAccountCreateResult event handler. Inside it, we access the event.result. If it’s the text error, we show an Alert dialog displaying a terse error message. Otherwise, we assume success, so we dispatch a new event called AccountCreateEvent with the result, cast to XML. The XML(result) cast is necessary because the user variable is typed in the Event.
If the @user.save! fails, we end up rescuing ActiveRecord::RecordInvalid. First, we delete the old logging code
. Then, we modify the format.xml block
—we’ll leave the format.html unmodified. We change the syntax from the single-line convention of { ... } to the multiline convention of do ... end. Inside the block, we check whether the @user.errors (which is an ActiveRecord::Errors) is empty
. If it’s non-empty, we render as XML the result of calling the new to_xml_full method that we added to ActiveRecord::Errors
. If it’s empty, something truly bizarre has happened (an error with no errors), so we render "error"
and ignore it. (If this was a real application, we would, of course, log the error.)
Next, we’ll create two new files on the Flex side: ServerErrors (to store the errors from Rails in) and ServerErrorValidator (a custom validator that displays the errors from Rails). First, ServerErrors; see listing 7.12.
Listing 7.12. app\flex\com\pomodo\validators\ServerErrors.as
package com.pomodo.validators { import mx.validators.Validator; import mx.validators.ValidationResult; public class ServerErrors { public static const BASE:String = ":base"; /** * The errors on specific fields (base errors are on the * BASE). The keys are the field Strings; the values are * Arrays of errors. */ private var _allErrors:Object; public function ServerErrors(errorsXML:XML) { _allErrors = {}; for each (var error:XML in errorsXML.error) { var field:String = error.@field; if (field == null || field == "") { field = BASE; } if (_allErrors[field] == null) { _allErrors[field] = [ createValidationResult(error.@message) ]; } else { var fieldErrors:Array = _allErrors[field]; fieldErrors.push( createValidationResult(error.@message)); } } } /** * Return an Array of the errors (just Strings) for the * field, an empty Array if none. */ public function getErrorsForField(field:String):Array { return _allErrors[field] == null ? [] : _allErrors[field]; } private function createValidationResult(message:String): ValidationResult { return new ValidationResult( true, "", "SERVER_VALIDATION_ERROR", message); } } }
. Then, we modify the format.xml block
—we’ll leave the format.html unmodified. We change the syntax from the single-line convention of { ... } to the multiline convention of do ... end. Inside the block, we check whether the @user.errors (which is an ActiveRecord::Errors) is empty
. If it’s non-empty, we render as XML the result of calling the new to_xml_full method that we added to ActiveRecord::Errors
. If it’s empty, something truly bizarre has happened (an error with no errors), so we render "error"
and ignore it. (If this was a real application, we would, of course, log the error.)