Hey there.
I’m trying to implement an automated tournament system for my game, but Cloud code is just behaving in very whack ways when I try to generate brackets once players have registered the tournament.
This is my Cloud Code Endpoint:
[CloudCodeFunction("StartTournament")]
public async Task<TournamentDTO> StartTournament(IExecutionContext context, IGameApiClient gameApiClient, string code)
{
_logger.LogInformation("Starting tournament: "+ code);
TournamentDTO tournamentDto = await GetTournamentByCode(context, gameApiClient, code);
_logger.LogTrace("Here");
tournamentDto.State = TournamentDTO.TournamentState.ONGOING;
if (tournamentDto.TournamentType != TournamentDTO.TournamentMode.GOLDEN_BOOT)
{
if (tournamentDto.TournamentType != TournamentDTO.TournamentMode.CUSTOM)
{
_logger.LogDebug("Generating brackets: "+ code);
tournamentDto.Brackets.Children = GenerateBrackets(tournamentDto);
}
}
tournamentDto.Brackets.Start(_logger, tournamentDto);
return UpdateTournament(context, gameApiClient, tournamentDto);
}
private async Task<TournamentDTO> GetTournamentByCode(IExecutionContext context, IGameApiClient gameApiClient, string code)
{
_logger.LogTrace("GetTournamentByCode");
ApiResponse<GetItemsResponse> apiResponse = await gameApiClient.CloudSaveData.GetCustomItemsAsync(context, context.ServiceToken, context.ProjectId, "Tournament"+code);
GetItemsResponse getItemsResponse = apiResponse.Data;
TournamentDTO tournamentDto = JsonConvert.DeserializeObject<TournamentDTO>(getItemsResponse.Results[0].Value.ToString());
_logger.LogDebug("Tournament Found: "+ LogifyTouranamentDto(tournamentDto));
return tournamentDto;
}
It prints the first log (Starting Tournameng + code), but then I get an error 500 when calling GetTournamentByCode without reaching any of the logs inside the method. Mind you, I’m calling this method inside other ClodeCode functions (create tournaments and addPlayers) and it works perfectly, it is only on this very specific method that it fails, although I’m treating the data the same way in those three methods. the stack trace really says nothing, in fact, if anything, it’s even more misleading:
HttpException`1: (500) HTTP/1.1 500 Internal Server Error
at Unity.Services.CloudCode.Internal.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.CloudCode.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) [0x00089] in .\Library\PackageCache\com.unity.services.cloudcode@2.5.1\Runtime\com.unity.services.cloudcode.internal\Http\ResponseHandler.cs:122
at Unity.Services.CloudCode.Internal.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.CloudCode.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary`2[TKey,TValue] statusCodeToTypeMap) [0x00001] in .\Library\PackageCache\com.unity.services.cloudcode@2.5.1\Runtime\com.unity.services.cloudcode.internal\Http\ResponseHandler.cs:226
at Unity.Services.CloudCode.Internal.Apis.CloudCode.CloudCodeApiClient.RunModuleAsync (Unity.Services.CloudCode.Internal.CloudCode.RunModuleRequest request, Unity.Services.CloudCode.Internal.Configuration operationConfiguration) [0x001fd] in .\Library\PackageCache\com.unity.services.cloudcode@2.5.1\Runtime\com.unity.services.cloudcode.internal\Apis\CloudCodeApi.cs:137
at Unity.Services.CloudCode.CloudCodeInternal.GetModuleResponseAsync (System.String module, System.String function, System.Collections.Generic.Dictionary`2[TKey,TValue] args) [0x00082] in .\Library\PackageCache\com.unity.services.cloudcode@2.5.1\Runtime\CloudCode.cs:243
at Unity.Services.CloudCode.CloudCodeInternal.GetRunModuleScriptResponse (System.String module, System.String function, System.Collections.Generic.Dictionary`2[TKey,TValue] args) [0x00047] in .\Library\PackageCache\com.unity.services.cloudcode@2.5.1\Runtime\CloudCode.cs:137
Rethrow as CloudCodeException: ServiceUnavailable
(500) HTTP/1.1 500 Internal Server Error
Error
An unknown server error occurred
The Cloud Code Log console only shows the logs that I added, and shows nothign about the error at hand, I extracted these logs from my Player.log
I’ve tried debugging this code in the most ridiculous way possible (moving the _logger.LogTrace(“Here”); line by line and even inside the utility method to see what’s even going on). But the result is always the same. _logger.LogTrace(“Here”); and _logger.LogTrace(“GetTournamentByCode”); are never called. I also tried reviewing the quotas for CloudSave API andI’m not exceeding the 600 calls per minute that it allows for these endpoints.
Now if I remove the variable assignation on line 5, and leave the line just as
await GetTournamentByCode(context, gameApiClient, code); and then instantiate a dummy TournamentDTO, it works.
This has been an incredibly frustrating issue and a total road block for this very core funcitonality, which my community anticipates greatly. I’m tryign my best not to vent here, but I’m one month away from release and you have to concede that CloudCode is not making any efforts in communicating properly what’s the issue.
I’m flaging this as a Bug because, even if this is an error from my side, something has to be done about this logging for the product to actually be usable.
Any idea what might be going wrong on this endpoint?