miros / exc_error Goto Github PK
View Code? Open in Web Editor NEWSimple error struct factory for Elixir
License: Other
Simple error struct factory for Elixir
License: Other
When I define MyError message function with string interpolation without inspect
ExcError.define MyError, [:str] do
@impl true
def message(str), do: "#{str} without inspect"
end
this test hangs
describe "MyError" do
test "test interpolation" do
error = {:error, %MyError{str: "foo"}}
assert_exc_error({:error, %MyError{}} = error)
end
end
1) test MyError test interpolation (MyTest)
test/my_test.exs:15
** (ExUnit.TimeoutError) test timed out after 60000ms. You can change the timeout:
1. per test by setting "@tag timeout: x" (accepts :infinity)
2. per test module by setting "@moduletag timeout: x" (accepts :infinity)
3. globally via "ExUnit.start(timeout: x)" configuration
4. by running "mix test --timeout x" which sets timeout
5. or by running "mix test --trace" which sets timeout to infinity
(useful when using IEx.pry/0)
where "x" is the timeout given as integer in milliseconds (defaults to 60_000).
code: assert_exc_error({:error, %MyError{}} = error)
stacktrace:
(elixir 1.11.2) lib/string/chars.ex:3: String.Chars.impl_for!/1
(elixir 1.11.2) lib/string/chars.ex:22: String.Chars.to_string/1
(data_io 0.1.0) lib/my_module.ex:9: MyError.message/1
test/my_test.exs:17: (test)
(ex_unit 1.11.2) lib/ex_unit/runner.ex:391: ExUnit.Runner.exec_test/1
(stdlib 3.13) timer.erl:166: :timer.tc/1
(ex_unit 1.11.2) lib/ex_unit/runner.ex:342: anonymous fn/4 in ExUnit.Runner.spawn_test_monitor/4
When I use inspect in string interpolation everything is OK
ExcError.define MyError, [:str] do
@impl true
def message(str), do: "#{inspect(str)} with inspect"
end
The trouble with dialyzer and ExcError, I'm specifying possible error for my function and launch mix dialyzer
module example below:
defmodule Test do
@moduledoc """
Documentation for Test.
"""
require ExcError
ExcError.define SomeTerribleError
@spec hello :: SomeTerribleError.t()
def hello do
%SomeTerribleError{message: "It's you :)"}
end
end
current result:
$ mix dialyzer
...
:0: Unknown type 'Elixir.Test.SomeTerribleError':t/0
expected result:
$ mix dialyzer
...
Well done, great job! There are no errors and warnings
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.