concept error in category elixir

This is an excerpt from Manning's book Phoenix in Action.
Respond gracefully to errors by having supervisors restart workers when they crash
If you get an error about the database not existing, run the following command from the command line to set up the test database. Note that you can force the environment you want Mix to run in by setting MIX_ENV in the command. (Here, you’ll run it in the test environment.)
The last Auction function you’ll test in this chapter is Auction.insert_item/1. This function takes the attributes of the item to insert into the database, and it returns {:ok, item} on success or {:error, changeset} on error. The following listing tests each of those paths.
Listing 14.15. Testing Auction.insert_item/1
defmodule AuctionTest do import Ecto.Query #1 # ... describe "insert_item/1" do test "adds an Item to the database" do count_query = from i in Item, select: count(i.id) #2 before_count = Repo.one(count_query) {:ok, _item} = Auction.insert_item(%{title: "test item"}) assert Repo.one(count_query) == before_count + 1 #3 end test "the Item in the database has the attributes provided" do attrs = %{title: "test item", description: "test description"} {:ok, item} = Auction.insert_item(attrs) assert item.title == attrs.title assert item.description == attrs.description #4 end test "it returns an error on error" do assert {:error, _changeset} = Auction.insert_item(%{foo: :bar}) end end end
Now you can test the red path—the path of errors. First, you’d like to ensure that no item will be created if the controller is passed bad params.

This is an excerpt from Manning's book Elixir in Action.
Fault-tolerance—A system has to keep working when something unforeseen happens. Unexpected errors occur, bugs creep in, components occasionally fail, network connections drop, or the entire machine where the system is running crashes. Whatever happens, you want to localize the impact of an error as much as possible, recover from the error, and keep the system running and providing service.
left_value = bob_pid right_value = Todo.Cache.server_process(cache, "alice") comparison_result = left_value != right_value if comparison_result == false do # raise an error end
In this section, we’ll discuss how to reduce the effect of an error on the entire system. The basic tools are processes, links, and supervisors, and the general approach is fairly simple. You always have to consider what will happen to the rest of the system if a process crashes due to an error, and you should take corrective measures when an error’s impact is too wide (when the error affects too many processes).

This is an excerpt from Manning's book The Little Elixir & OTP Guidebook.
Destructuring is useful for declaring preconditions in your programs. What do I mean by that? Let’s take reading a file as an example. If most of your logic depends on the file being readable, then it makes sense to find out as soon as possible whether an error occurs with file reading. It would also be helpful to know what kind of error occurred. Figure 2.4 shows a snippet from the File.read/1 documentation.
# ... output omitted Error: Stop testing on first error. (Check '-h keep_going'). Done! (Exit status: warning) Summary: 1 errors, 1/1 interleaving explored
In the examples that follow, you’ll see the kinds of errors Concuerror can pick out.

This is an excerpt from Manning's book Elixir in Action.
Fault tolerance— A system has to keep working when something unforeseen happens. Unexpected errors occur, bugs creep in, components occasionally fail, network connections drop, or the entire machine where the system is running crashes. Whatever happens, we want to localize the impact of an error as much as possible, recover from the error, and keep the system running and providing service.
iex(1)> File.open!("nonexistent_file") ** (File.Error) could not open non_existing_file: no such file or directory
In this section, we’ll discuss how to reduce the effect of an error on the entire system. The basic tools are processes, links, and supervisors, and the general approach is fairly simple. You always have to consider what will happen to the rest of the system if a process crashes due to an error; and you should take corrective measures when an error’s impact is too wide (the error affects too many processes).
The whole point of let it crash is to leave recovery of unexpected errors to supervisors. But if you can predict an error and you have a way to deal with it, there’s no reason to let the process crash. Here’s a simple example. Look at the :get request in the database worker: