@@ -1119,7 +1119,7 @@ public static Collection<FunctionMetadata> ReadFunctionMetadata(ScriptHostConfig
1119
1119
continue ;
1120
1120
}
1121
1121
1122
- ValidateFunctionName ( functionName ) ;
1122
+ ValidateName ( functionName ) ;
1123
1123
1124
1124
string json = File . ReadAllText ( functionConfigPath ) ;
1125
1125
JObject functionConfig = JObject . Parse ( json ) ;
@@ -1196,27 +1196,38 @@ private Collection<FunctionMetadata> LoadProxyRoutes(string proxiesJson)
1196
1196
1197
1197
foreach ( var route in routes . Routes )
1198
1198
{
1199
- var proxyMetadata = new FunctionMetadata ( ) ;
1200
-
1201
- var json = new JObject
1199
+ try
1202
1200
{
1203
- { "authLevel" , "anonymous" } ,
1204
- { "name" , "req" } ,
1205
- { "type" , "httptrigger" } ,
1206
- { "direction" , "in" } ,
1207
- { "Route" , route . UrlTemplate . TrimStart ( '/' ) } ,
1208
- { "Methods" , new JArray ( route . Methods . Select ( m => m . Method . ToString ( ) ) . ToArray ( ) ) }
1209
- } ;
1201
+ // Proxy names should follow the same naming restrictions as in function names.
1202
+ ValidateName ( route . Name , true ) ;
1210
1203
1211
- BindingMetadata bindingMetadata = BindingMetadata . Create ( json ) ;
1204
+ var proxyMetadata = new FunctionMetadata ( ) ;
1212
1205
1213
- proxyMetadata . Bindings . Add ( bindingMetadata ) ;
1206
+ var json = new JObject
1207
+ {
1208
+ { "authLevel" , "anonymous" } ,
1209
+ { "name" , "req" } ,
1210
+ { "type" , "httptrigger" } ,
1211
+ { "direction" , "in" } ,
1212
+ { "Route" , route . UrlTemplate . TrimStart ( '/' ) } ,
1213
+ { "Methods" , new JArray ( route . Methods . Select ( m => m . Method . ToString ( ) ) . ToArray ( ) ) }
1214
+ } ;
1214
1215
1215
- proxyMetadata . Name = route . Name ;
1216
- proxyMetadata . ScriptType = ScriptType . Unknown ;
1217
- proxyMetadata . IsProxy = true ;
1216
+ BindingMetadata bindingMetadata = BindingMetadata . Create ( json ) ;
1218
1217
1219
- proxies . Add ( proxyMetadata ) ;
1218
+ proxyMetadata . Bindings . Add ( bindingMetadata ) ;
1219
+
1220
+ proxyMetadata . Name = route . Name ;
1221
+ proxyMetadata . ScriptType = ScriptType . Unknown ;
1222
+ proxyMetadata . IsProxy = true ;
1223
+
1224
+ proxies . Add ( proxyMetadata ) ;
1225
+ }
1226
+ catch ( Exception ex )
1227
+ {
1228
+ // log any unhandled exceptions and continue
1229
+ AddFunctionError ( FunctionErrors , route . Name , Utility . FlattenException ( ex , includeSource : false ) , isFunctionShortName : true ) ;
1230
+ }
1220
1231
}
1221
1232
1222
1233
return proxies ;
@@ -1263,11 +1274,11 @@ internal static bool TryParseFunctionMetadata(string functionName, JObject funct
1263
1274
return true ;
1264
1275
}
1265
1276
1266
- internal static void ValidateFunctionName ( string functionName )
1277
+ internal static void ValidateName ( string name , bool isProxy = false )
1267
1278
{
1268
- if ( ! FunctionNameValidationRegex . IsMatch ( functionName ) )
1279
+ if ( ! FunctionNameValidationRegex . IsMatch ( name ) )
1269
1280
{
1270
- throw new InvalidOperationException ( string . Format ( "'{0}' is not a valid function name." , functionName ) ) ;
1281
+ throw new InvalidOperationException ( string . Format ( "'{0}' is not a valid {1} name." , name , isProxy ? "proxy" : "function" ) ) ;
1271
1282
}
1272
1283
}
1273
1284
@@ -1437,6 +1448,11 @@ internal static void ValidateFunction(FunctionDescriptor function, Dictionary<st
1437
1448
}
1438
1449
}
1439
1450
1451
+ if ( httpFunctions . ContainsKey ( function . Name ) )
1452
+ {
1453
+ throw new InvalidOperationException ( $ "The function or proxy name '{ function . Name } ' must be unique within the function app.") ;
1454
+ }
1455
+
1440
1456
httpFunctions . Add ( function . Name , httpTrigger ) ;
1441
1457
}
1442
1458
}
0 commit comments