Skip to content

Commit

Permalink
Erlang Error Index Content
Browse files Browse the repository at this point in the history
Summary:
* W0011
* W0012
* W0013

Differential Revision: D49188397

fbshipit-source-id: 199cfbeb159bf327533f5cf7c6fa17029229f02b
  • Loading branch information
robertoaloi authored and facebook-github-bot committed Sep 12, 2023
1 parent 5239d2c commit d35585b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
20 changes: 20 additions & 0 deletions website/docs/erlang-error-index/w/W0011.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ sidebar_position: 11
---

# W0011 - Application Get Env

## Error

```erlang title="/app_a/src/main.erl"
-module(main).

get_app_b_env() ->
application:get_env(app_b, key).
%% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: module `main` belongs to app `app_a`, but reads env for `app_b`
```

## Explanation

The error message is indicating that a module belonging to an application `app_a` is attempting at reading the environment for a different application `app_b`.

Erlang provides an [API](https://www.erlang.org/doc/man/application#get_env-2) to access the application environment of a different application from the one the calling module (or, to be more precise, the calling process executing that module) belongs to.

This pattern can lead to subtle bugs since the target application (`app_b` in the above example) could not yet be loaded at the time of the call or it could be missing from a specific [release](https://www.erlang.org/doc/design_principles/release_structure.html).

Sometimes accessing an other applicatioon environment is a totally acceptable behaviour. In those cases, the warning can be silenced via the [standard `elp:ignore` mechanirm](../erlang-error-index.md#ignoring-diagnostics).
34 changes: 33 additions & 1 deletion website/docs/erlang-error-index/w/W0012.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,36 @@
sidebar_position: 12
---

# W0012 - Missing Compile Warn Missing Spec
# W0012 - Missing `warn_missing_spec` compiler attribute

## Error

```erlang
-module(main).

-compile([export_all, nowarn_export_all]).
%% ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Please add "-compile(warn_missing_spec)." or
%% | "-compile(warn_missing_spec_all)." to the module.
%% | If exported functions are not all specced, they need to be specced.
```

## Explanation

The error is indicating that the given module does not have a `warn_missing_spec` or `warn_missing_spec_all` compiler attribute but it should have one.

This diagnostic can be particularly useful for large code bases where type information (via `-spec` attributes) are added incrementally and it's not possible to specify the option globally.

To fix this warning you can add one of the following compiler attributes:

```erlang
-compile(warn_missing_spec). %% To enable warnings on exported functions only
-compile(warn_missing_spec_all). %% To enable warnings on all functions
```

Notice that multiple compiler attributes can be listed using the same attribute. For example:

```erlang
-compile([export_all, nowarn_export_all, warn_missing_spec]).
```

For more information about compiler attributes and their meaning see [here](https://www.erlang.org/doc/man/compile).
13 changes: 13 additions & 0 deletions website/docs/erlang-error-index/w/W0013.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@ sidebar_position: 13
---

# W0013 - Misspelled Attribute

## Error

```erlang
-dyalizer({nowarn_function, f/0}).
%% ^^^^^^^^ error: misspelled attribute, saw 'dyalizer' but expected 'dialyzer'
```

## Explanation

The message is indicating that the attribute name is suspiciously similar to a _known_ one and it could therefore contain a typo.

To fix the error either correct the attribute spelling or ignore the warning via [the standard `elp:ignore` mechanism](../erlang-error-index.md#ignoring-diagnostics).

0 comments on commit d35585b

Please sign in to comment.