ScenicFramework / scenic

Core Scenic library
Apache License 2.0
1.99k stars 137 forks source link

Handle a non-configured assets module #240

Closed axelson closed 3 years ago

axelson commented 3 years ago

What problem does this feature solve?

Currently if you forget to configure you assets module with a line like:

config :scenic, :assets, module: MyApp.Assets

You will get an error like:

06:26:33.064 [error] GenServer #PID<0.402.0> terminating
** (UndefinedFunctionError) function nil.library/0 is undefined
    nil.library()
    (scenic 0.11.0-beta.0) lib/scenic/assets/static.ex:315: Scenic.Assets.Static.meta/1
    (scenic 0.11.0-beta.0) lib/scenic/primitive/style/font.ex:56: Scenic.Primitive.Style.Font.validate/1
    (nimble_options 0.3.7) lib/nimble_options.ex:577: NimbleOptions.validate_type/3
    (nimble_options 0.3.7) lib/nimble_options.ex:427: NimbleOptions.validate_option/3
    (nimble_options 0.3.7) lib/nimble_options.ex:407: NimbleOptions.reduce_options/2
    (elixir 1.12.2) lib/enum.ex:4280: Enumerable.List.reduce/3
    (elixir 1.12.2) lib/enum.ex:2431: Enum.reduce_while/3
Last message: {:continue, {:_init, [supervisor: #PID<0.396.0>, stop_pid: #PID<0.396.0>, child_supervisor: nil, name: "_main_", module: MyApp.Scene.NewScene, parent: #PID<0.366.0>, param: nil, viewport: %Scenic.ViewPort{name: :main_viewport, pid: #PID<0.366.0>, script_table: #Reference<0.538338776.1541013505.150752>, size: {700, 600}}, root_sup: #PID<0.368.0>, opts: [theme: :dark]]}}
State: nil

What is your proposed solution?

Instead I think that scenic should detect this condition and raise a helpful error message.

Although perhaps there should be a default assets module that will raise if you try to actually use any assets, although i think that's only a good thing if that is always known at compile time. So I think for now always raising at compile time is the best approach.

boydm commented 3 years ago

Done.

This is now fixed in the v0.11 branch. Nice error messages along with example code showing what to do.

axelson commented 3 years ago

Looks great! Here's the commit for any future readers: https://github.com/boydm/scenic/commit/c373212e07bd99e0c633f847781875589dfc4d54