@@ -468,51 +468,48 @@ defmodule Mix.Release do
468468 { sys_config , runtime_config? } =
469469 merge_provider_config ( release , sys_config , config_provider_path )
470470
471- path = Path . join ( release . version_path , "sys.config" )
472-
473- args = [ runtime_config? , sys_config ]
474- format = "%% coding: utf-8~n%% RUNTIME_CONFIG=~s~n~tw.~n"
475- File . mkdir_p! ( Path . dirname ( path ) )
476- File . write! ( path , IO . chardata_to_string ( :io_lib . format ( format , args ) ) )
477-
478- case :file . consult ( path ) do
479- { :ok , _ } ->
471+ case consultable_sys_config ( sys_config ) do
472+ { :ok , contents } ->
473+ path = Path . join ( release . version_path , "sys.config" )
474+ args = [ runtime_config? , contents ]
475+ format = "%% coding: utf-8~n%% RUNTIME_CONFIG=~s~n~ts.~n"
476+ File . mkdir_p! ( Path . dirname ( path ) )
477+ File . write! ( path , IO . chardata_to_string ( :io_lib . format ( format , args ) ) )
480478 :ok
481479
482- { :error , reason } ->
483- invalid =
484- for { app , kv } <- sys_config ,
485- { key , value } <- kv ,
486- not valid_config? ( value ) ,
487- do: """
488-
489- Application: #{ inspect ( app ) }
490- Key: #{ inspect ( key ) }
491- Value: #{ inspect ( value ) }
492- """
493-
494- message =
495- case invalid do
496- [ ] ->
497- "Could not read configuration file. Reason: #{ inspect ( reason ) } "
498-
499- _ ->
500- "Could not read configuration file. It has invalid configuration terms " <>
501- "such as functions, references, and pids. Please make sure your configuration " <>
502- "is made of numbers, atoms, strings, maps, tuples and lists. The following entries " <>
503- "are wrong:\n #{ Enum . join ( invalid ) } "
504- end
505-
480+ { :error , message } ->
506481 { :error , message }
507482 end
508483 end
509484
510- defp valid_config? ( m ) when is_map ( m ) ,
511- do: Enum . all? ( Map . delete ( m , :__struct__ ) , & valid_config? / 1 )
485+ defp consultable_sys_config ( sys_config ) do
486+ contents =
487+ Enum . map_intersperse ( sys_config , ?, , fn { app , kv } ->
488+ kv =
489+ Enum . map_intersperse ( kv , ?, , fn { key , value } ->
490+ case Mix.Utils . consultable ( value ) do
491+ { :ok , value } -> [ ?{ , :io_lib . print ( key ) , ?, , value , ?} ]
492+ { :error , term , reason } -> throw ( { :error , app , key , term , reason } )
493+ end
494+ end )
512495
513- defp valid_config? ( l ) when is_list ( l ) , do: Enum . all? ( l , & valid_config? / 1 )
514- defp valid_config? ( t ) when is_tuple ( t ) , do: Enum . all? ( Tuple . to_list ( t ) , & valid_config? / 1 )
515- defp valid_config? ( o ) , do: is_number ( o ) or is_atom ( o ) or is_binary ( o )
496+ [ ?{ , :io_lib . print ( app ) , ?, , ?[ , kv , ?] , ?} ]
497+ end )
498+
499+ { :ok , [ ?[ , contents , ?] ] }
500+ catch
501+ { :error , app , key , value , reason } ->
502+ message = """
503+ Could not write configuration file because it has invalid terms
504+
505+ Application: #{ inspect ( app ) }
506+ Key: #{ inspect ( key ) }
507+ Invalid value: #{ inspect ( value ) }
508+ Reason: #{ reason }
509+ """
510+
511+ { :error , message }
512+ end
516513
517514 defp merge_provider_config ( % { config_providers: [ ] } , sys_config , _ ) , do: { sys_config , false }
518515
0 commit comments