rustler icon indicating copy to clipboard operation
rustler copied to clipboard

Obscure error messages

Open AviKav opened this issue 1 year ago • 3 comments

I came across some confusing error messages while working on https://github.com/AviKav/silicon.ex:


I got ** (ErlangError) Erlang error: :invalid_struct when I forgot to rename

#[derive(NifStruct)]
#[module = "Silicon.FormatOptions"]
struct FormatOptions {

to

#[derive(NifStruct)]
#[module = "Silicon.Options.Format"]
struct FormatOptions {

I've gotten

** (ErlangError) Erlang error: "Could not decode field :image_options on %FormatOptions{}"

for having the wrong value all the way in image_options.shadow_adder.background.

%FormatOptions{} was a red herring since I thought it was an Elixir struct's old name that was hanging around for some reason, when it actuality it was a Rust type.


I think these error messages should be specific of where or what the issue is.

As of current I'd need to provide the user with a validation function in order to give useful error information. This is a third place, in addition to typespecs and Rust types, where I'd need to maintain type information. Unless something like https://github.com/Qqwy/elixir-type_check is used.

AviKav avatar Jan 02 '24 01:01 AviKav

Do you have concrete suggestions?

filmor avatar Feb 11 '24 00:02 filmor

  1. Erlang error: :invalid_struct should detail which rust struct it's having difficulty compiling. a. And include why if there are multiple possible reasons.
  2. Erlang error: "Could not decode field :image_options on %FormatOptions{}" should: a. Explicitly say "rust struct" and not use Elixir map notation when talking about Rust structs. b. Rather than stating the root field, state either the leaf field where term conversion is failing or the path to said leaf.

AviKav avatar Feb 11 '24 00:02 AviKav

Sorry about that

AviKav avatar Feb 11 '24 00:02 AviKav