@@ -922,7 +922,7 @@ public static Collection<FunctionMetadata> ReadFunctionMetadata(ScriptHostConfig
922
922
continue ;
923
923
}
924
924
925
- ValidateFunctionName ( functionName ) ;
925
+ ValidateName ( functionName ) ;
926
926
927
927
string json = File . ReadAllText ( functionConfigPath ) ;
928
928
JObject functionConfig = JObject . Parse ( json ) ;
@@ -999,27 +999,38 @@ private Collection<FunctionMetadata> LoadProxyRoutes(string proxiesJson)
999
999
1000
1000
foreach ( var route in routes . Routes )
1001
1001
{
1002
- var proxyMetadata = new FunctionMetadata ( ) ;
1003
-
1004
- var json = new JObject
1002
+ try
1005
1003
{
1006
- { "authLevel" , "anonymous" } ,
1007
- { "name" , "req" } ,
1008
- { "type" , "httptrigger" } ,
1009
- { "direction" , "in" } ,
1010
- { "Route" , route . UrlTemplate . TrimStart ( '/' ) } ,
1011
- { "Methods" , new JArray ( route . Methods . Select ( m => m . Method . ToString ( ) ) . ToArray ( ) ) }
1012
- } ;
1004
+ // Proxy names should follow the same naming restrictions as in function names.
1005
+ ValidateName ( route . Name , true ) ;
1013
1006
1014
- BindingMetadata bindingMetadata = BindingMetadata . Create ( json ) ;
1007
+ var proxyMetadata = new FunctionMetadata ( ) ;
1015
1008
1016
- proxyMetadata . Bindings . Add ( bindingMetadata ) ;
1009
+ var json = new JObject
1010
+ {
1011
+ { "authLevel" , "anonymous" } ,
1012
+ { "name" , "req" } ,
1013
+ { "type" , "httptrigger" } ,
1014
+ { "direction" , "in" } ,
1015
+ { "Route" , route . UrlTemplate . TrimStart ( '/' ) } ,
1016
+ { "Methods" , new JArray ( route . Methods . Select ( m => m . Method . ToString ( ) ) . ToArray ( ) ) }
1017
+ } ;
1017
1018
1018
- proxyMetadata . Name = route . Name ;
1019
- proxyMetadata . ScriptType = ScriptType . Unknown ;
1020
- proxyMetadata . IsProxy = true ;
1019
+ BindingMetadata bindingMetadata = BindingMetadata . Create ( json ) ;
1021
1020
1022
- proxies . Add ( proxyMetadata ) ;
1021
+ proxyMetadata . Bindings . Add ( bindingMetadata ) ;
1022
+
1023
+ proxyMetadata . Name = route . Name ;
1024
+ proxyMetadata . ScriptType = ScriptType . Unknown ;
1025
+ proxyMetadata . IsProxy = true ;
1026
+
1027
+ proxies . Add ( proxyMetadata ) ;
1028
+ }
1029
+ catch ( Exception ex )
1030
+ {
1031
+ // log any unhandled exceptions and continue
1032
+ AddFunctionError ( FunctionErrors , route . Name , Utility . FlattenException ( ex , includeSource : false ) , isFunctionShortName : true ) ;
1033
+ }
1023
1034
}
1024
1035
1025
1036
return proxies ;
@@ -1087,11 +1098,11 @@ internal static bool HttpRoutesConflict(HttpTriggerAttribute httpTrigger, HttpTr
1087
1098
return httpTrigger . Methods . Intersect ( otherHttpTrigger . Methods ) . Any ( ) ;
1088
1099
}
1089
1100
1090
- internal static void ValidateFunctionName ( string functionName )
1101
+ internal static void ValidateName ( string name , bool isProxy = false )
1091
1102
{
1092
- if ( ! FunctionNameValidationRegex . IsMatch ( functionName ) )
1103
+ if ( ! FunctionNameValidationRegex . IsMatch ( name ) )
1093
1104
{
1094
- throw new InvalidOperationException ( string . Format ( "'{0}' is not a valid function name." , functionName ) ) ;
1105
+ throw new InvalidOperationException ( string . Format ( "'{0}' is not a valid {1} name." , name , isProxy ? "proxy" : "function" ) ) ;
1095
1106
}
1096
1107
}
1097
1108
@@ -1277,6 +1288,11 @@ internal static void ValidateFunction(FunctionDescriptor function, Dictionary<st
1277
1288
}
1278
1289
}
1279
1290
1291
+ if ( httpFunctions . ContainsKey ( function . Name ) )
1292
+ {
1293
+ throw new InvalidOperationException ( $ "The function or proxy name '{ function . Name } ' must be unique within the function app.") ;
1294
+ }
1295
+
1280
1296
httpFunctions . Add ( function . Name , httpTrigger ) ;
1281
1297
}
1282
1298
}
0 commit comments