module not loading msgpack erlang - module

Attempting to test msgpack as dependency in a simple release package using rebar in Erlang / OTP.
My folder structure is as follows
Project -> Apps -> myapp -> ebin
-> src
-> deps -> msgpack (folder)
-> rebar (exe)
-> rebar config
-> rel -> reltool.config
-> files (folder)
-> mynode (folder)
Code snippet of the function & its handle_call:
num_pokes() ->
gen_server:call(?MODULE, num_pokes).
handle_call(num_pokes, _From, State = #state{ num_pokes = PokeCount }) ->
MP = msgpack:pack(PokeCount),
io:format (" Message is packed : ~p~n", MP),
MuP = msgpack:unpack_stream(MP),
io:format (" Message is now UNpacked : ~p~n", MuP),
io:format (" Pokecount : ~p~n", PokeCount),
{reply, PokeCount, State};
Error showing: when num_pokes() is called
=ERROR REPORT==== 10-Apr-2015::12:44:53 ===
** Generic server myapp_server terminating
** Last message in was num_pokes
** When Server state == {state,2}
** Reason for termination ==
** {'module could not be loaded',
[{msgpack,pack,[2],[]},
{myapp_server,handle_call,3,[{file,"src/myapp_server.erl"},{line,32}]},
{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]}
** exception exit: {{undef,
[{msgpack,pack,[2],[]},
{myapp_server,handle_call,3,
[{file,"src/myapp_server.erl"},{line,32}]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
{gen_server,call,[myapp_server,num_pokes]}}
in function gen_server:call/2 (gen_server.erl, line 182)

Pass -pa deps/msgpack/ebin to erl as command-line arguments. Then it will find the compiled modules.

Folder structure pointing towards mspack was shown by me as ./deps (dependencies folder). It should be ./deps/msgpack

Related

'Module build failed: Error: Couldn't find preset "es2015" relative to directory' from newly created gatsby project

I have created a project following these steps:
npm install -g gatsby
gatsby new dev-blog
cd dev-blog
npm install
Then I try to start by project by
gatsby develop --host localhost --port 9000
At this point it throws an exception:
Failed to require /Users/antkong/wd/blogs/gatsby/dev-blog/html.js
./html.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/Users/antkong/wd"
How can I fix this problem?
Edit
OS: OSX 10.12.4
Darwin mymac.local 16.5.0 Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64
npm: 3.10.10
node: 6.10.2
Full stacktrace:
❯❯ npm run develop
> gatsby-starter-default#1.0.0 develop /Users/antkong/wd/blogs/gatsby/dev-blog
> gatsby develop
Failed to require /Users/antkong/wd/blogs/gatsby/dev-blog/html.js
./html.js
Module build failed: Error: Couldn't find preset "es2015" relative to directory "/Users/antkong/wd"
at /Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/options/option-manager.js:293:19
at Array.map (native)
at OptionManager.resolvePresets (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
at OptionManager.mergePresets (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/options/option-manager.js:264:10)
at OptionManager.mergeOptions (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/options/option-manager.js:249:14)
at OptionManager.init (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
at File.initOptions (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/index.js:212:65)
at new File (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/file/index.js:135:24)
at Pipeline.transform (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
at transpile (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-loader/lib/index.js:46:20)
at /Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-loader/lib/fs-cache.js:79:18
at ReadFileContext.callback (/Users/antkong/wd/blogs/gatsby/dev-blog/node_modules/babel-loader/lib/fs-cache.js:15:14)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)
# (webpack)-require/lib/webpackRequireEntrypoint.js 1:20-41
I am also using nvm
❯❯ nvm list
-> v6.10.2
system
default -> v6 (-> v6.10.2)
node -> stable (-> v6.10.2) (default)
stable -> 6.10 (-> v6.10.2) (default)
iojs -> N/A (default)
lts/* -> lts/boron (-> v6.10.2)
lts/argon -> v4.8.2 (-> N/A)
lts/boron -> v6.10.2
gabsty new does not create a .babelrc that is needed by babel. The error is caused by the missing .babelrc.
Here is the content of my .babelrc:
{
"presets": ["react", "es2015", "stage-0"],
"env": {
"development": {
"presets": ["react-hmre"]
}
}
}

How to build a release archive with rebar3 together with lager

I am trying to build an OTP release with rebar3. Under the project there are multiple applications. And all those applications will use lager as a logging framework. So I tried the rebar.config like this
{erl_opts, [debug_info,
{i, "apps"}]
}.
{deps, [lager]}.
{relx, [{release, { myrel, "0.0.1" },
[app1,
app2,
sasl]},
{sys_config, "./config/sys.config"},
{vm_args, "./config/vm.args"},
{dev_mode, false},
{include_erts, false},
{extended_start_script, true}]
}.
{profiles, [{prod, [{relx, [{dev_mode, false},
{include_src, false},
{include_erts, true},
{system_libs, true}
]}]
}]
}.
The dependence likes this
===> Verifying dependencies...
├─ lager─3.2.1 (hex package)
│ └─ goldrush─0.1.8 (hex package)
├─ app1─1.0.0 (project app)
└─ app2─0.1.0 (project app)
'rebar3 release' looks fine. No error shown.
However, when I run 'rebar3 as prod tar', I found that there is no lager (and goldrush) included the archive (ie. myrel-0.0.1.tar.gz). Therefore when I run it in production system with command 'bin/myrel console', I got the following error..
=ERROR REPORT==== 23-Nov-2016::13:23:01 ===
** Generic server sccp_user terminating
** Last message in was {set,1,undefined}
** When Server state == {su_state,lookup}
** Reason for termination ==
** {'module could not be loaded',
[{lager_config,get,[{lager_event,loglevel},{0,[]}],[]},
.....
Any idea how to solve this ?

No mapping using babel and browserify in PlayFramework 2.5

I am writing a project that is based on the seed at git#github.com:maximebourreau/play-reactjs-es6-seed.git
It appears to work with the 2.3 play framework, but I am getting errors using the 2.5 framework.
When I try to load a page, it get the following error:
RuntimeException: No mapping for /path/to/root/target/web/browserify/main.js
The full stack trace is at the bottom of the message.
This is the file that browserify is writing, but it seems that play does not know how to map it to a URL. I was not able to find anything that says where the file should be written or how to add a new mapping. I am also happy to use a plugin to do the translation.
Where should I be writing the file, or how should I tell play how to map the file?
My build.sbt is
name := """myProject"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
)
val browserifyTask = taskKey[Seq[File]]("Run browserify")
val browserifyOutputDir = settingKey[File]("Browserify output directory")
browserifyOutputDir := target.value / "web" / "browserify"
browserifyTask := {
println("Running browserify");
val outputFile = browserifyOutputDir.value / "main.js"
browserifyOutputDir.value.mkdirs
"./node_modules/.bin/browserify -t [ babelify --presets [ es2015 react ] ] app/assets/javascripts/main.jsx -o "+outputFile.getPath !;
List(outputFile)
}
sourceGenerators in Assets <+= browserifyTask
resourceDirectories in Assets += browserifyOutputDir.value
My routes file is
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# An example controller showing a sample home page
GET / controllers.HomeController.index
# An example controller showing how to use dependency injection
GET /count controllers.CountController.count
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
POST /assessment controllers.AsyncController.assessment
#
# Play can't find files in node_modules in 2.5+
#GET /node_modules/*file controllers.NodeModulesController.at(file)
#GET /node_modules/*file controllers.NodeModulesController.at(file: String)
GET /node_modules/*file controllers.NodeModulesController.versioned(file: String)
#GET /node_modules/*file controllers.Assets.versioned(path="/node_modules", file:Asset)
The stack trace is
scala.sys.package$.error(package.scala:27)
sbt.Mapper$$anonfun$fail$1.apply(PathMapper.scala:37)
sbt.Mapper$$anonfun$fail$1.apply(PathMapper.scala:37)
sbt.Alternatives$$anon$1$$anonfun$$bar$1$$anonfun$apply$3.apply(PathMapper.scala:117)
sbt.Alternatives$$anon$1$$anonfun$$bar$1$$anonfun$apply$3.apply(PathMapper.scala:117)
scala.Option.orElse(Option.scala:257)
sbt.Alternatives$$anon$1$$anonfun$$bar$1.apply(PathMapper.scala:117)
sbt.Alternatives$$anon$1$$anonfun$$bar$1.apply(PathMapper.scala:117)
sbt.PathFinder$$anonfun$pair$1.apply(Path.scala:135)
sbt.PathFinder$$anonfun$pair$1.apply(Path.scala:135)
scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:251)
scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:251)
scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
sbt.PathFinder.pair(Path.scala:135)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1$$anonfun$9$$anonfun$10$$anonfun$apply$4.apply(SbtJsTask.scala:292)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1$$anonfun$9$$anonfun$10$$anonfun$apply$4.apply(SbtJsTask.scala:286)
com.typesafe.sbt.web.SbtWeb$.withActorRefFactory(SbtWeb.scala:595)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1$$anonfun$9$$anonfun$10.apply(SbtJsTask.scala:285)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1$$anonfun$9$$anonfun$10.apply(SbtJsTask.scala:284)
scala.collection.immutable.Stream$$anonfun$map$1.apply(Stream.scala:376)
scala.collection.immutable.Stream$$anonfun$map$1.apply(Stream.scala:376)
scala.collection.immutable.Stream$Cons.tail(Stream.scala:1085)
scala.collection.immutable.Stream$Cons.tail(Stream.scala:1077)
scala.collection.immutable.Stream.foldLeft(Stream.scala:563)
scala.concurrent.Future$.sequence(Future.scala:491)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1$$anonfun$9.apply(SbtJsTask.scala:303)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1$$anonfun$9.apply(SbtJsTask.scala:272)
com.typesafe.sbt.web.incremental.package$.syncIncremental(package.scala:228)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1.apply(SbtJsTask.scala:271)
com.typesafe.sbt.jse.SbtJsTask$$anonfun$jsSourceFileTask$1.apply(SbtJsTask.scala:257)
scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
sbt.std.Transform$$anon$4.work(System.scala:63)
sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
sbt.Execute.work(Execute.scala:237)
sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:745)
You must change two lines in build.sbt
List(outputFile) to Nil
and
resourceDirectories in Asset += browserifyOutputDir.value
to
unmanagedResources in Assets += baseDirectory.value / "target/web/browserify/main.js"
For example:
browserifyTask := {
println("Running browserify");
val outputFile = browserifyOutputDir.value / "main.js"
browserifyOutputDir.value.mkdirs
"./node_modules/.bin/browserify -t [ babelify --presets [ es2015 react ] ] app/assets/javascripts/main.jsx -o "+outputFile.getPath !;
Nil
}
sourceGenerators in Assets <+= browserifyTask
unmanagedResources in Assets += baseDirectory.value / "target/web/browserify/main.js"
I ran accross the same error message, and almost same stacktrace,
after starting a project from the same git repo: git#github.com:maximebourreau/play-reactjs-es6-seed.git
The latest version of the repo is using play 2.5 and works fine, so
I don't think play version is a problem.
I noticed that the error was mentioning [sbt-jshint] somewhere,
and removing this line from project/plugins.sbt fixed the problem for me:
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")

problems with Scraping a Website with Elixir

I'm trying to get a simple hound test working with my app, I figured out its an error with selenium. This is the code:
In mix.exs:
defmodule Scraper.Mixfile do
use Mix.Project
def project do
[app: :scraper,
version: "0.0.1",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end
# Configuration for the OTP application
#
# Type `mix help compile.app` for more information
def application do
[applications: [:logger, :httpoison, :hound]]
end
# Dependencies can be Hex packages:
#
# {:mydep, "~> 0.3.0"}
#
# Or git/path repositories:
#
# {:mydep, git: "https://github.com/elixir-lang/mydep.git", tag: "0.1.0"}
#
# Type `mix help deps` for more examples and options
defp deps do
[
{:httpoison, "~> 0.7"},
{:floki, "~> 0.7"},
{:hound, "~> 0.7"}
]
end
end
In lib/scraper.ex
defmodule Example do
use Hound.Helpers
def run do
Hound.start_session
IO.inspect "Iniciando"
navigate_to "http://akash.im"
IO.inspect page_title()
Hound.end_session
end
end
In config/config.exs
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for third-
# party users, it should be done in your mix.exs file.
# Sample configuration:
#
# config :logger, :console,
# level: :info,
# format: "$date $time [$level] $metadata$message\n",
# metadata: [:user_id]
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
# Define how long the application will wait between failed attempts (in miliseconds)
config :hound, retry_time: 100000
# Start with selenium driver (default)
config :hound, driver: "selenium"
Starting a webdriver server
java -jar selenium-server-standalone-2.45.0.jar
Run app:
/scraper$ iex -S mix
Erlang/OTP 18 [erts-7.1] [source] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]
Interactive Elixir (1.0.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Example.run
** (exit) exited in: :gen_server.call(Hound.SessionServer, {:find_or_create_session, #PID<0.148.0>}, 60000)
** (EXIT) an exception was raised:
** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :timeout}}
(hound) lib/hound/request_utils.ex:43: Hound.RequestUtils.send_req/4
(hound) lib/hound/session_server.ex:22: Hound.SessionServer.handle_call/3
(stdlib) gen_server.erl:629: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:661: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
11:26:13.971 [error] GenServer Hound.SessionServer terminating
Last message: {:find_or_create_session, #PID<0.148.0>}
State: #HashDict<[]>
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :timeout}}
(hound) lib/hound/request_utils.ex:43: Hound.RequestUtils.send_req/4
(hound) lib/hound/session_server.ex:22: Hound.SessionServer.handle_call/3
(stdlib) gen_server.erl:629: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:661: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
(stdlib) gen_server.erl:212: :gen_server.call/3
(scraper) lib/scraper.ex:37: Example.run/0
iex(1)>
The request timed out in this case, as can be seen from the line
** (MatchError) no match of right hand side value: {:error, %HTTPoison.Error{id: nil, reason: :timeout}}
If you look at the stack trace, it indicates the error is at
(hound) lib/hound/request_utils.ex:43: Hound.RequestUtils.send_req/4
And if you open up hound source, on line 43 of lib/hound/request_utils.ex you see
case type do
:get ->
{:ok, resp} = HTTPoison.get(url, headers, #http_options)
:post ->
{:ok, resp} = HTTPoison.post(url, body, headers, #http_options)
:delete ->
{:ok, resp} = HTTPoison.delete(url, headers, #http_options)
end
This code expects a response, and crashes otherwise. There's a timeout error in your case, causing the crash.
Please check if the website up and reachable when you run the test, and retry.

Screenshots using Selenium IDE Firefox plugin

Using Selenium IDE Firefox plugin, I want to take automated screenshots.
The test script contains of two lines:
Command: open; Target: http://www.google.com
Command: captureEntirePageScreenshotAndWait
The log shows:
[info] Executing: |open | http://www.google.com | |
[info] Executing: |captureEntirePageScreenshotAndWait | | |
[error] Unexpected Exception: [Exception... "Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]" nsresult: "0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH)" location: "JS frame :: chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js :: <TOP_LEVEL> :: line 3045" data: no]. toString -> function toString() { [native code] }, message -> Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath], result -> 2152857601, name -> NS_ERROR_FILE_UNRECOGNIZED_PATH, filename -> chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js, lineNumber -> 3045, columnNumber -> 0, inner -> null, data -> null, location -> JS frame :: chrome://selenium-ide/content/selenium-core/scripts/selenium-api.js :: <TOP_LEVEL> :: line 3045
How to get screenshots?
Setting the file path correctly solved it. The path needs to be set as follows:
(Windows:)
Command: captureEntirePageScreenshotAndWait; Target: D:\\Screenshots\\test.png
(Linux:)
Command: captureEntirePageScreenshotAndWait; Target: \\Screenshots\\test.png
In this example, the folder 'Screenshots' must exist.