There is a library that simplifies the process of making GenServers: https://hex.pm/packages/exactor It in fact has such a 'strict' mode similar to this, for showing prior design.
You could also do it yourself as a user, don't use GenServer, instead 'implement' GenServer, I.E. ```elixir @behaviour GenServer ``` Then at least Dialyzer will yell at you if not everything is implemented. I, personally, would like a strict mode, however I'm unsure of just how it should be done. Your changes are good but I'd probably also add an after_compile hook to walk the module AST (not hard to do, but it is erlang AST at that point, not elixir) and verify the functions exist in addition to your changes. Make a `defmodule_GenServer` macro would be easier though, and that could be done easily as a library. On Friday, September 23, 2016 at 1:26:46 PM UTC-6, alco wrote: > > Hi, > > We all love the ability to `use GenServer` in order to provide default > stubs for callback functions, saving us time and effort of writing the same > boilerplate over and over again. > > However, I'm sure many of you have also been bitten by this very feature > where you made a typo in the signature of init/1 or handle_info/2 and was > left scratching your head wondering why the gen server's state looks so > weird or whether it receives any messages sent to it. > > I'd like to propose an addition that will make the default stubs stricter > in terms of handling unexpected input. The idea is basically adding the > `strict` option to the `use GenServer` call. When that option is supplied > with value `true`, the following changes will take effect: > > 1. There will be no default implementation of init/1. If the user > forgets to implement it or implements it incorrectly by supplying a > different number of arguments, the compiler will warn about the missing > init/1 implementation. > > 2. The default implementation of handle_info/1 will exit on any incoming > message, in the same way handle_cast/2 and handle_call/3 already do. > > The change will be backwards-compatible if we make `strict: false` the > default. However, we should mention in the docs that calling `use > GenServer, strict: true` is the recommended way for any serious purpose and > that `use GenServer` should be reserved for playground or throw-away code. > > Here's a proof of concept – > https://github.com/elixir-lang/elixir/compare/master...alco:alco/strict-gen-server > > Best regards, > Alex > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/21309273-bf4f-47c7-a4d3-f480df39a822%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
