setop

setop

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 ?

Showing Posts 1 to 3

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>
setop

setop OP

Thanks a lots, it works like a charm.

Followup question : what application is exactly started ? Also what is the difference between starting and not starting an application ? After all why this application is not started by Mix each time by default ?

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews