Skip to content

Commit c99e1cd

Browse files
author
José Valim
committed
Do not crash IEx on :init.stop
1 parent 402a338 commit c99e1cd

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

lib/elixir/lib/macro.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ defmodule Macro do
131131
valid_alias?(charlist) ->
132132
:alias
133133
true ->
134-
case :elixir_config.get(:identifier_tokenizer).tokenize(charlist) do
134+
case :elixir_config.safe_get(:identifier_tokenizer, String.Tokenizer).tokenize(charlist) do
135135
{kind, _acc, [], _, _, special} ->
136136
if kind == :identifier and not :lists.member(?@, special) do
137137
:callable

lib/elixir/lib/uri.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule URI do
4242
"""
4343
@spec default_port(binary) :: nil | non_neg_integer
4444
def default_port(scheme) when is_binary(scheme) do
45-
:elixir_config.get({:uri, scheme})
45+
:elixir_config.safe_get({:uri, scheme}, nil)
4646
end
4747

4848
@doc """

lib/elixir/src/elixir_config.erl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-module(elixir_config).
22
-compile({no_auto_import, [get/1]}).
3-
-export([new/1, delete/1, put/2, get/1, update/2, get_and_put/2]).
3+
-export([new/1, delete/1, put/2, get/1, safe_get/2, update/2, get_and_put/2]).
44
-export([start_link/0, init/1, handle_call/3, handle_cast/2,
55
handle_info/2, code_change/3, terminate/2]).
66
-behaviour(gen_server).
@@ -19,9 +19,15 @@ put(Key, Value) ->
1919
gen_server:call(?MODULE, {put, Key, Value}).
2020

2121
get(Key) ->
22-
case ets:lookup(?MODULE, Key) of
22+
[{_, Value}] = ets:lookup(?MODULE, Key),
23+
Value.
24+
25+
safe_get(Key, Default) ->
26+
try ets:lookup(?MODULE, Key) of
2327
[{_, Value}] -> Value;
24-
[] -> nil
28+
[] -> Default
29+
catch
30+
_:_ -> Default
2531
end.
2632

2733
update(Key, Fun) ->

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ tokenize(String, Line, Column, Opts) ->
142142
existing_atoms_only=ExistingAtomsOnly,
143143
check_terminators=CheckTerminators,
144144
preserve_comments=PreserveComments,
145-
identifier_tokenizer=elixir_config:get(identifier_tokenizer)
145+
identifier_tokenizer=elixir_config:safe_get(identifier_tokenizer, 'Elixir.String.Tokenizer')
146146
}).
147147

148148
tokenize(String, Line, Opts) ->

lib/elixir/src/elixir_utils.erl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,17 @@ relative_to_cwd(Path) ->
9696
characters_to_list(Data) when is_list(Data) ->
9797
Data;
9898
characters_to_list(Data) ->
99-
try elixir_config:get(bootstrap) of
99+
case elixir_config:safe_get(bootstrap, true) of
100100
true -> unicode:characters_to_list(Data);
101101
false -> 'Elixir.String':to_charlist(Data)
102-
catch
103-
_:_ -> unicode:characters_to_list(Data)
104102
end.
105103

106104
characters_to_binary(Data) when is_binary(Data) ->
107105
Data;
108106
characters_to_binary(Data) ->
109-
try elixir_config:get(bootstrap) of
110-
true -> unicode:characters_to_binary(Data);
107+
case elixir_config:safe_get(bootstrap, true) of
108+
true -> unicode:characters_to_binary(Data);
111109
false -> 'Elixir.List':to_string(Data)
112-
catch
113-
_:_ -> unicode:characters_to_binary(Data)
114110
end.
115111

116112
%% Returns the caller as a stacktrace entry.

0 commit comments

Comments
 (0)