@@ -1093,59 +1093,66 @@ public static Collection<FunctionMetadata> ReadFunctionMetadata(IEnumerable<stri
1093
1093
traceWriter . Info ( msg ) ;
1094
1094
}
1095
1095
1096
- foreach ( var scriptDir in functionDirectories )
1096
+ foreach ( var functionDirectory in functionDirectories )
1097
1097
{
1098
- string functionName = null ;
1099
- try
1098
+ var function = ReadFunctionMetadata ( functionDirectory , traceWriter , logger , functionErrors , settingsManager , functionWhitelist ) ;
1099
+ if ( function != null )
1100
1100
{
1101
- // read the function config
1102
- string functionConfigPath = Path . Combine ( scriptDir , ScriptConstants . FunctionMetadataFileName ) ;
1103
- string json = null ;
1104
- try
1105
- {
1106
- json = File . ReadAllText ( functionConfigPath ) ;
1107
- }
1108
- catch ( FileNotFoundException )
1109
- {
1110
- // not a function directory
1111
- continue ;
1112
- }
1101
+ functions . Add ( function ) ;
1102
+ }
1103
+ }
1113
1104
1114
- functionName = Path . GetFileName ( scriptDir ) ;
1115
- if ( functionWhitelist != null &&
1116
- ! functionWhitelist . Contains ( functionName , StringComparer . OrdinalIgnoreCase ) )
1117
- {
1118
- // a functions filter has been specified and the current function is
1119
- // not in the filter list
1120
- continue ;
1121
- }
1105
+ return functions ;
1106
+ }
1122
1107
1123
- ValidateName ( functionName ) ;
1108
+ public static FunctionMetadata ReadFunctionMetadata ( string functionDirectory , TraceWriter traceWriter , ILogger logger , Dictionary < string , Collection < string > > functionErrors , ScriptSettingsManager settingsManager = null , IEnumerable < string > functionWhitelist = null )
1109
+ {
1110
+ string functionName = null ;
1124
1111
1125
- JObject functionConfig = JObject . Parse ( json ) ;
1112
+ try
1113
+ {
1114
+ // read the function config
1115
+ string json = null ;
1116
+ if ( ! TryReadFunctionConfig ( functionDirectory , out json ) )
1117
+ {
1118
+ // not a function directory
1119
+ return null ;
1120
+ }
1126
1121
1127
- string functionError = null ;
1128
- FunctionMetadata functionMetadata = null ;
1129
- if ( ! TryParseFunctionMetadata ( functionName , functionConfig , traceWriter , logger , scriptDir , settingsManager , out functionMetadata , out functionError ) )
1130
- {
1131
- // for functions in error, log the error and don't
1132
- // add to the functions collection
1133
- AddFunctionError ( functionErrors , functionName , functionError ) ;
1134
- continue ;
1135
- }
1136
- else if ( functionMetadata != null )
1137
- {
1138
- functions . Add ( functionMetadata ) ;
1139
- }
1122
+ functionName = Path . GetFileName ( functionDirectory ) ;
1123
+ if ( functionWhitelist != null &&
1124
+ ! functionWhitelist . Contains ( functionName , StringComparer . OrdinalIgnoreCase ) )
1125
+ {
1126
+ // a functions filter has been specified and the current function is
1127
+ // not in the filter list
1128
+ return null ;
1140
1129
}
1141
- catch ( Exception ex )
1130
+
1131
+ ValidateName ( functionName ) ;
1132
+
1133
+ JObject functionConfig = JObject . Parse ( json ) ;
1134
+
1135
+ string functionError = null ;
1136
+ FunctionMetadata functionMetadata = null ;
1137
+ if ( ! TryParseFunctionMetadata ( functionName , functionConfig , traceWriter , logger , functionDirectory , settingsManager , out functionMetadata , out functionError ) )
1142
1138
{
1143
- // log any unhandled exceptions and continue
1144
- AddFunctionError ( functionErrors , functionName , Utility . FlattenException ( ex , includeSource : false ) , isFunctionShortName : true ) ;
1139
+ // for functions in error, log the error and don't
1140
+ // add to the functions collection
1141
+ AddFunctionError ( functionErrors , functionName , functionError ) ;
1142
+ return null ;
1143
+ }
1144
+ else if ( functionMetadata != null )
1145
+ {
1146
+ return functionMetadata ;
1145
1147
}
1146
1148
}
1149
+ catch ( Exception ex )
1150
+ {
1151
+ // log any unhandled exceptions and continue
1152
+ AddFunctionError ( functionErrors , functionName , Utility . FlattenException ( ex , includeSource : false ) , isFunctionShortName : true ) ;
1153
+ }
1147
1154
1148
- return functions ;
1155
+ return null ;
1149
1156
}
1150
1157
1151
1158
internal Collection < FunctionMetadata > ReadProxyMetadata ( ScriptHostConfiguration config , ScriptSettingsManager settingsManager = null )
@@ -1177,6 +1184,27 @@ internal Collection<FunctionMetadata> ReadProxyMetadata(ScriptHostConfiguration
1177
1184
return null ;
1178
1185
}
1179
1186
1187
+ internal static bool TryReadFunctionConfig ( string scriptDir , out string json , IFileSystem fileSystem = null )
1188
+ {
1189
+ json = null ;
1190
+ fileSystem = fileSystem ?? FileUtility . Instance ;
1191
+
1192
+ // read the function config
1193
+ string functionConfigPath = Path . Combine ( scriptDir , ScriptConstants . FunctionMetadataFileName ) ;
1194
+ try
1195
+ {
1196
+ json = fileSystem . File . ReadAllText ( functionConfigPath ) ;
1197
+ }
1198
+ catch ( IOException ex ) when
1199
+ ( ex is FileNotFoundException || ex is DirectoryNotFoundException )
1200
+ {
1201
+ // not a function directory
1202
+ return false ;
1203
+ }
1204
+
1205
+ return true ;
1206
+ }
1207
+
1180
1208
private Collection < FunctionMetadata > LoadProxyRoutes ( string proxiesJson )
1181
1209
{
1182
1210
var proxies = new Collection < FunctionMetadata > ( ) ;
0 commit comments