[erlang-questions] xref and cowboy callbacks

Guilherme Andrade g@REDACTED
Wed May 3 21:43:35 CEST 2017


Hi,

> But it's also telling me that my cowboy callbacks are unused exports:
>
> Warning: init_handler:allowed_methods/2 is unused export (Xref)
> Warning: init_handler:content_types_accepted/2 is unused export (Xref)
> ...

Based on the list of callbacks, I'm assuming these are rest handlers.
Unfortunately, almost all of the rest handler callback functions are
optional[1] and not part of a particular behavior (as of cowboy 1.x,
anyway.) As the calling-back itself is done dynamically - either using
apply/3 or M:F(A, ...), with M only known at runtime - and the functions
are not part of any explicitly defined behavior, there's no way xref can
know or assume the callback functions are actually going to be used.

I usually use '-ignore_xref({F,Arity})' directives as a workaround. Perhaps
defining a cowboy rest handler behavior with all optional callbacks marked
as such would do the trick, but if I recall correctly optional callback
annotations are a fairly recent feature.

Regards,


[1]: https://ninenines.eu/docs/en/cowboy/1.0/manual/cowboy_rest/


On 3 May 2017 at 17:06, <duncan@REDACTED> wrote:

> I'm new at using xref and must be missing something obvious. I did some
> refactoring of my app and decided to run xref to find where I'd forgot to
> delete/add something. It worked great and I found mistakes I'd made and
> fixed them, But it's also telling me that my cowboy callbacks are unused
> exports:
>
> Warning: init_handler:allowed_methods/2 is unused export (Xref)
> Warning: init_handler:content_types_accepted/2 is unused export (Xref)
> Warning: init_handler:handle_json/2 is unused export (Xref)
> Warning: init_handler:init/3 is unused export (Xref)
> Warning: init_handler:rest_init/2 is unused export (Xref)
> Warning: openc2_handler:allowed_methods/2 is unused export (Xref)
> Warning: openc2_handler:content_types_accepted/2 is unused export (Xref)
> Warning: openc2_handler:handle_json/2 is unused export (Xref)
> Warning: openc2_handler:init/3 is unused export (Xref)
> Warning: openc2_handler:rest_init/2 is unused export (Xref)
> Warning: status_handler:allowed_methods/2 is unused export (Xref)
> Warning: status_handler:init/3 is unused export (Xref)
> Warning: status_handler:rest_init/2 is unused export (Xref)
> Warning: status_handler:to_html/2 is unused export (Xref)
> Warning: status_ok_handler:allowed_methods/2 is unused export (Xref)
> Warning: status_ok_handler:content_types_provided/2 is unused export
> (Xref)
> Warning: status_ok_handler:init/3 is unused export (Xref)
>
> init_handler, openc2_handler, status_handler, and status_ok_handler are
> all modules in the cowboy routes:
>
> Routes =
>     [
>       {
>         '_'  %virtual hostname (any host name)
>       , [
>           {"/status", status_handler, []}
>         , {"/ok", status_ok_handler, []}  % returns ok if service working
>         , {"/openc2", openc2_handler, []}    % handles the meat of openc2
>         , {"/init", init_handler, []}    % handles starting/restarting the
> sim
>         ]
>       }
>     ],
>
> I assume I'm not configuring xref correctly to let it know about cowboy. I
> run xref using rebar 3 from the app directory. I assumed rebar3's knowledge
> about dependencies would inform xref (which it must or I'd get a host of
> other errors) - but then why do these warnings appear?
>
> Not sure if related but I also get:
> Warning: ocas_app:start/0 is unused export (Xref)
> This is the main start routine so I guess it makes sense it isn't called
> from anything else.
>
> Duncan Sparrell
> sFractal Consulting LLC
> iPhone, iTypo, iApologize
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>


-- 
Guilherme
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170503/9cbad29b/attachment.htm>


More information about the erlang-questions mailing list