** (Mix) Could not start application rumbl: Rumbl.start(:normal, []) - phoenix-framework

If you have the next error in your terminal:
(Mix) Could not start application rumbl: Rumbl.start(:normal, []) returned an error: shutdown: failed to start child: Rumbl.Repo
(EXIT) an exception was raised:
(UndefinedFunctionError) undefined function Rumbl.Repo.start_link/0
(rumbl) Rumbl.Repo.start_link()
(stdlib) supervisor.erl:358: :supervisor.do_start_child/2
(stdlib) supervisor.erl:341: :supervisor.start_children/3
(stdlib) supervisor.erl:307: :supervisor.init_children/2
(stdlib) gen_server.erl:328: :gen_server.init_it/6
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

Just add this before last end, in your repo.ex file:
def start_link do
{:ok, self}
end

In lib/rumbl.ex, comment out the line that starts the repository:
# Start the Ecto repository
# supervisor(Rumbl.Repo, []),

Related

Phoenix 1.4.0-dev generated channel test fails with compile error

I am developing a web app with the Phoenix framework in a Docker container. Here are the relevant lines in the dockerfile for how phoenix is getting installed:
RUN git clone https://github.com/phoenixframework/phoenix
RUN cd /home/user/phoenix/installer/ && MIX_ENV=prod mix do archive.build, archive.install --force
That all works fine. I can generate a new phoenix project with the command:
mix phx.new hello_phoenix
However, when I generate a new channel with:
mix phx.gen.channel hello_channel
and add this line to the user socket file
channel "hello_channel:lobby", HelloPhoenixWeb.HelloChannelChannel
and then run
mix test
I get the following errors:
warning: Phoenix.ChannelTest.socket/2 is deprecated, please call socket/3 instead
(phoenix) lib/phoenix/test/channel_test.ex:234: Phoenix.ChannelTest."MACRO-socket"/3
(elixir) src/elixir_dispatch.erl:186: :elixir_dispatch.expand_macro_fun/6
(elixir) src/elixir_dispatch.erl:149: :elixir_dispatch.do_expand_import/6
(elixir) src/elixir_dispatch.erl:81: :elixir_dispatch.dispatch_import/5
(elixir) src/elixir_expand.erl:539: :elixir_expand.expand_arg/2
(stdlib) lists.erl:1354: :lists.mapfoldl/3
(elixir) src/elixir_expand.erl:548: :elixir_expand.expand_args/2
(elixir) src/elixir_expand.erl:646: :elixir_expand.expand_remote/7
(elixir) src/elixir_dispatch.erl:207: :elixir_dispatch.expand_quoted/6
(elixir) src/elixir_expand.erl:10: :elixir_expand.expand/2
(elixir) src/elixir_expand.erl:489: :elixir_expand.expand_block/4
(elixir) src/elixir_expand.erl:39: :elixir_expand.expand/2
(elixir) src/elixir_clauses.erl:19: :elixir_clauses.def/2
(elixir) src/elixir_def.erl:146: :elixir_def."-store_definition/10-lc$^0/1-0-"/2
(elixir) src/elixir_def.erl:146: :elixir_def.store_definition/10
test/hello_phoenix_web/channels/hello_channel_channel_test.exs:6: (module)
(elixir) src/elixir_compiler.erl:85: :elixir_compiler.dispatch/6
..
== Compilation error in file test/hello_phoenix_web/channels/hello_channel_channel_test.exs ==
** (CaseClauseError) no case clause matching: [{"/socket", HelloPhoenixWeb.UserSocket, [], [{["socket", "websocket"], {:websocket, HelloPhoenixWeb.UserSocket, [serializer: [{Phoenix.Socket.V1.JSONSerializer, "~> 1.0.0"}, {Phoenix.Socket.V2.JSONSerializer, "~> 2.0.0"}], timeout: 60000, transport_log: false, compress: false]}}]}]
(phoenix) lib/phoenix/test/channel_test.ex:240: Phoenix.ChannelTest.first_socket!/1
(phoenix) lib/phoenix/test/channel_test.ex:213: Phoenix.ChannelTest.build_socket/4
(phoenix) expanding macro: Phoenix.ChannelTest.socket/2
test/hello_phoenix_web/channels/hello_channel_channel_test.exs:8: HelloPhoenixWeb.HelloChannelChannelTest.__ex_unit_setup_1/1
(elixir) expanding macro: Kernel.|>/2
test/hello_phoenix_web/channels/hello_channel_channel_test.exs:9: HelloPhoenixWeb.HelloChannelChannelTest.__ex_unit_setup_1/1
(elixir) lib/code.ex:677: Code.require_file/2
(elixir) lib/kernel/parallel_compiler.ex:201: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6
Here's the code for the channel file that was generated by the mix phx.gen.channel task:
defmodule HelloPhoenixWeb.HelloChannelChannel do
use HelloPhoenixWeb, :channel
def join("hello_channel:lobby", payload, socket) do
if authorized?(payload) do
{:ok, socket}
else
{:error, %{reason: "unauthorized"}}
end
end
# Channels can be used in a request/response fashion
# by sending replies to requests from the client
def handle_in("ping", payload, socket) do
{:reply, {:ok, payload}, socket}
end
# It is also common to receive messages from the client and
# broadcast to everyone in the current topic (hello_channel:lobby).
def handle_in("shout", payload, socket) do
broadcast socket, "shout", payload
{:noreply, socket}
end
# Add authorization logic here as required.
defp authorized?(_payload) do
true
end
end
And here's the code for the test that was generated also:
defmodule HelloPhoenixWeb.HelloChannelChannelTest do
use HelloPhoenixWeb.ChannelCase
alias HelloPhoenixWeb.HelloChannelChannel
setup do
{:ok, _, socket} =
socket("user_id", %{some: :assign})
|> subscribe_and_join(HelloChannelChannel, "hello_channel:lobby")
{:ok, socket: socket}
end
test "ping replies with status ok", %{socket: socket} do
ref = push socket, "ping", %{"hello" => "there"}
assert_reply ref, :ok, %{"hello" => "there"}
end
test "shout broadcasts to hello_channel:lobby", %{socket: socket} do
push socket, "shout", %{"hello" => "all"}
assert_broadcast "shout", %{"hello" => "all"}
end
test "broadcasts are pushed to the client", %{socket: socket} do
broadcast_from! socket, "broadcast", %{"some" => "data"}
assert_push "broadcast", %{"some" => "data"}
end
end
I have this problem with an actual project I'm working on and also with a test project I spun up to isolate the problem.
What is causing the compilation error with the test that the generator made?
Phoenix framework 1.4 is still in development state so bugs are pretty much not surprising. Phoenix framwork 1.3.x is current stable version, you should use that. And if you know what your are doing with 1.4-dev build than you should raise a issue on Phoenix Framework github repo.

Running main in prolog

I got following code (from this tutorial)
main:-
open(’houses.txt’,read,Str),
read_houses(Str,Houses),
close(Str),
write(Houses), nl.
read_houses(Stream,[]):-
at_end_of_stream(Stream).
read_houses(Stream,[X|L]):-
\+ at_end_of_stream(Stream),
read(Stream,X),
read_houses(Stream,L).
houses.txt:
gryffindor.
hufflepuff.
ravenclaw.
slytherin.
I load it like this:
$ swipl -s flp18-log.pl
The problem comes when I want to start main "function" ->
?- main.
ERROR: Undefined procedure: main/1
ERROR: However, there are definitions for:
ERROR: main/0
ERROR:
ERROR: In:
ERROR: [9] main([])
ERROR: [8] prolog_main:main at /usr/local/Cellar/swi-prolog/HEAD-e6bbda4/libexec/lib/swipl-7.7.12/library/main.pl:82
ERROR: [7] <user>
Exception: (9) main([]) ?
I spent hours figuring out what's wrong. Unsuccessfully. Can you help?
Is:
open('houses.txt',read,Str)
with ', not with ’.

no function clause matching in Phoenix.Socket.Message.from_map!/1 when connecting a socket

** (exit) exited in: Phoenix.Endpoint.CowboyWebSocket.resume()
** (EXIT) an exception was raised:
** (FunctionClauseError) no function clause matching in Phoenix.Socket.Message.from_map!/1
(phoenix) lib/phoenix/socket/message.ex:22: Phoenix.Socket.Message.from_map!(["16", "16", "public:subtopic", "phx_join", %{}])
(phoenix) lib/phoenix/transports/websocket.ex:106: Phoenix.Transports.WebSocket.ws_handle/3
(phoenix) lib/phoenix/endpoint/cowboy_websocket.ex:77: Phoenix.Endpoint.CowboyWebSocket.websocket_handle/3
(cowboy) /home/anil/ex_pusher_lite-master/deps/cowboy/src/cowboy_websocket.erl:588: :cowboy_websocket.handler_call/7
(phoenix) lib/phoenix/endpoint/cowboy_websocket.ex:49: Phoenix.Endpoint.CowboyWebSocket.resume/3
(cowboy) /home/anil/ex_pusher_lite-master/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
Phoenix.Socket.Message.from_map!() takes a map and converts it into a message struct. Somehow, you're passing a list into it, which is why you're getting an error stating that there isn't a version of Phoenix.Socket.Message.from_map!() that accepts a list.

Parse.com CloudCode beforeSave trigger errors

Context: parse.com CloudCode, executing beforeSave() trigger on data object object update.
Getting a rash of unexplained errors in simple trigger function (code below). The errors are mostly
Result: Uncaught undefined
but there are also several
Result: Execution timed out
The code is simple, I have checked it to the point where I don't think this is an error due to the code, but including it anyway since I know people will ask to see it.
This seems (seems!) to be an issue in Parse itself, which I've been unable to solve.
Parse.Cloud.beforeSave("LogoItem", function(request, response) {
var name = request.object.get("productName");
if (typeof name == "undefined") {
name = "";
}
request.object.set("lowercaseName", name.toLowerCase());
response.success(); // Tells parse not to cancel save
});
My question is, has anyone seen this and been able to get any handle on a solution?
Below is some additional detail (logs from parse) that likely won't be too useful (but never know)...
E2016-03-14T14:12:26.306Z] - v643 Ran job ShopSenseJob with:
Input: {"plan":"paid"}
Result: ERROR: startDownloadItems() failed with error [undefined: undefined] undefined: undefined
E2016-03-14T14:11:01.536Z] - v643 before_save triggered for LogoItem as master:
Input: {"original":{"activeURL":"http://api.shopstyle.com/action/apiVisitRetailer?id=486671765\u0026pid=uid4009-26060253-59","category":5,"createdAt":"2016-03-14T13:41:07.487Z","imageURL":"https://resources.shopstyle.com/pim/aa/92/aa9286b799d7640f276657fa5e41ee92_best.jpg","importMarkerTag":6624,"lowercaseName":"mid rise skinny with knee holes in marie vintage blue","objectId":"8o9e8nMF7m","productName":"Mid Rise Skinny With Knee Holes In Marie Vintage Blue","referenceURL":"http://www.shopstyle.com/p/7-for-all-mankind-mid-rise-skinny-with-knee-holes-in-marie-vintage-blue/486671765?pid=uid4009-26060253-59","ssBrandId":3,"ssBrandName":"7 For All Mankind","ssDate":{"__type":"Date","iso":"2014-12-05T00:00:00.000Z"},"ssId":486671765,"ssRetailerId":193,"thumbnailURL":"https://resources.shopstyle.com/pim/aa/92/aa9286b799d7640f276657fa5e41ee92_best.jpg","updatedAt":"2016-03-14T13:41:07.487Z"},"update":{"importMarkerTag":1556}}
Result: Execution timed out
E2016-03-14T14:10:21.498Z] - v643 Ran job ShopSenseJob with:
Input: {}
Result: ERROR: startDownloadItems() failed with error [undefined: undefined] undefined: undefined
E2016-03-14T14:08:18.638Z] - v643 before_save triggered for LogoItem as master:
Input: {"original":{"activeURL":"http://api.shopstyle.com/action/apiVisitRetailer?id=490062821\u0026pid=uid4009-26060253-59","category":2,"createdAt":"2016-03-14T13:40:12.971Z","imageURL":"https://resources.shopstyle.com/pim/20/cb/20cb7387834dd02ac9d950bde0f57b83_best.jpg","importMarkerTag":1556,"lowercaseName":"baggu basic tote in brown","objectId":"I4UTiUMnUG","productName":"Baggu Basic Tote In Brown","referenceURL":"http://www.shopstyle.com/p/baggu-basic-tote-in-brown/490062821?pid=uid4009-26060253-59","ssBrandId":-1,"ssBrandName":"","ssDate":{"__type":"Date","iso":"2014-12-03T00:00:00.000Z"},"ssId":490062821,"ssRetailerId":193,"thumbnailURL":"https://resources.shopstyle.com/pim/20/cb/20cb7387834dd02ac9d950bde0f57b83_best.jpg","updatedAt":"2016-03-14T14:06:12.708Z"},"update":{"importMarkerTag":1556}}
Result: Uncaught undefined
E2016-03-14T14:08:18.225Z] - v643 Ran job ShopSenseJob with:
Input: {}
Result: ERROR: startDownloadItems() failed with error [undefined: undefined] undefined: undefined
E2016-03-14T14:06:12.824Z] - v643 before_save triggered for LogoItem as master:
Input: {"original":{"activeURL":"http://api.shopstyle.com/action/apiVisitRetailer?id=489915836\u0026pid=uid4009-26060253-59","category":2,"createdAt":"2016-03-14T13:40:13.193Z","imageURL":"https://resources.shopstyle.com/pim/14/ef/14ef17ff769227c4293892e770fcf50a_best.jpg","importMarkerTag":1556,"lowercaseName":"basic tote in black","objectId":"JQ7GuRjfgH","productName":"Basic Tote In Black","referenceURL":"http://www.shopstyle.com/p/baggu-basic-tote-in-black/489915836?pid=uid4009-26060253-59","ssBrandId":25820,"ssBrandName":"Baggu","ssDate":{"__type":"Date","iso":"2014-12-02T00:00:00.000Z"},"ssId":489915836,"ssRetailerId":193,"thumbnailURL":"https://resources.shopstyle.com/pim/14/ef/14ef17ff769227c4293892e770fcf50a_best.jpg","updatedAt":"2016-03-14T14:06:10.013Z"},"update":{"importMarkerTag":1556}}
Result: Execution timed out
E2016-03-14T14:05:23.844Z] - v643 Ran job ShopSenseJob with:
Input: {}
Result: ERROR: startDownloadItems() failed with error [undefined: undefined] undefined: undefined

node.js script fails - TypeError: Object 0 has no method 'on' - Mac to Arduino UNO

when I attempt to run this uvsensor.js script from this plot.ly tutorial I encounter this error message. What is the best way to resolve it?
uv-sensor-tutorial $ node uvsensor.js
1421612122362 Device(s) /dev/cu.usbmodem1411
1421612125588 Connected /dev/cu.usbmodem1411
1421612125588 Repl Initialized
>> { streamstatus: 'All Streams Go!',
url: 'https://plot.ly/~micahstubbs/46',
message: '',
warning: '',
filename: 'uv sensing nodey arduino!',
error: '' }
/Users/m/workspace/arduino-projects/uv-sensor-tutorial/uvsensor.js:76
refLevel.on("data", function() {
^
TypeError: Object 0 has no method 'on'
at /Users/m/workspace/arduino-projects/uv-sensor-tutorial/uvsensor.js:76:14
at /Users/m/node_modules/plotly/index.js:87:17
at IncomingMessage.<anonymous> (/Users/m/node_modules/plotly/index.js:255:9)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
The best way to resolve it is to find out why refLevel is being assigned 0 instead of the object you think it should be.

Resources