Skip to content

Display a warning if a source module is not mapped #3

Description

@amclain

User Story

As a developer, I want to be notified if a source module doesn't have a mapping so that I have awareness that my program can deadlock.

Description

The following code will cause a deadlock if the source module (__MODULE__) isn't mapped to a target. Since this design is the proxy pattern, the deadlock is normal and expected behavior, as resolve(__MODULE__) resolves to MyInterface.

defmodule MyInterface do
  use Resolve

  def some_command, do: resolve(__MODULE__).some_command
end 

However, a developer can either forget to set or accidentally remove a mapping in this case. It would be convenient for Resolve to notify the developer when a mapping doesn't exist for a proxy module. However, we don't want to notify for all missing mappings, as falling back to the original module is desired in non-proxy scenarios.

Design

Add a warn_if_not_mapped boolean flag that will display a warning at compile time if a mapping in this module is not set.

defmodule MyInterface do
  use Resolve, warn_if_not_mapped: true

  def some_command, do: resolve(__MODULE__).some_command
end 
warning: Resolve has no mapping for MyInterface
  filename.ex:4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions