setop

setop

Run FastSanitizer in a mix task ends with "no process" error

Hi,

I’m trying to use FastSanitizer in a Mix Task, with the following code :

defmodule Mix.Tasks.HelloTask do

  @impl Mix.Task
  def run(_) do
    html = """
<p>blah</p>
"""
    IO.puts FastSanitize.basic_html(html)
  end
end

I end up with the following error :

** (exit) exited in: NimblePool.checkout(FastHtml.Pool)
    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (nimble_pool 0.1.0) lib/nimble_pool.ex:261: NimblePool.exit!/3
    (fast_html 2.0.4) lib/fast_html.ex:125: :fast_html.find_and_use_port/3
    (fast_sanitize 0.2.2) lib/fast_sanitize/fragment.ex:8: FastSanitize.Fragment.to_tree/1
    (fast_sanitize 0.2.2) lib/fast_sanitize/sanitizer.ex:30: FastSanitize.Sanitizer.scrub/2
    (testelixir 0.1.0) lib/hellotask.ex:10: Mix.Tasks.HelloTask.run/1
    (mix 1.11.3) lib/mix/task.ex:394: Mix.Task.run_task/3
    (mix 1.11.3) lib/mix/cli.ex:84: Mix.CLI.run_task/2

I tried to “start an application”, as suggested by the error message, but I did not manage to solve the issue that way.
I tried to setup async task, as suggested by some search on the forum, but I did not manage to solve the issue either.

What do I miss ?

Marked As Solved

APB9785

APB9785

Creator of ECSx

Mix tasks, by default, don’t start the application. But FastSanitize.basic_html is meant to be called inside a running app. You can tell the task to start your app like this:

defmodule Mix.Tasks.HelloTask do
  use Mix.Task

  @impl Mix.Task
  def run(_) do
    Mix.Task.run("app.start")

    html = """
    <p>blah</p>
    """

    {:ok, res} = FastSanitize.basic_html(html)

    IO.puts(res)
  end
end

and then it should work OK:

$ mix hello_task
Compiling 1 file (.ex)
<p>blah</p>

Also Liked

APB9785

APB9785

Creator of ECSx

The one you built - in your example it seems to be called testelixir.

Most Elixir applications work by spawning a bunch of processes in the BEAM (Erlang virtual machine). Those processes will keep running (holding state and waiting to receive messages) until the application is shut down. Obviously, if you don’t start the application, then these processes will not exist.

Because most Mix tasks do not require the app to be started. If it was the default, then a lot of unnecessary work would be done in those cases, and the task would take longer to run. Instead, you get to choose whether to start or not based on your needs.

In your case, the library FastSanitize (and its dependencies) spawn BEAM processes and send/receive messages with them. Therefore, if you want to use the functionality of the library in a Mix task, you must start the application, otherwise when it comes time to send a message to the process, you will get an error that the process does not exist.

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement