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 ?
Trending in Questions
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
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
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
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
APB9785
Mix tasks, by default, don’t start the application. But
FastSanitize.basic_htmlis meant to be called inside a running app. You can tell the task to start your app like this:and then it should work OK:
setop
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
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.