#Hey, I am triggering a cloud code

1 messages ยท Page 1 of 1 (latest)

mossy parrot
#

Hey. By a module patch do you mean you made changes to that module? And are you seeing the error in the Cloud Code Logs page?

viral depot
#

Yes and yes, sorry for the confusion.

mossy parrot
#

Do other functions from the module work if called manually? Not sure why there is a 500 error, could be some edge case failure which we didn't account for. Is there any more info you could share about the change?

viral depot
#

I have yet to grasp manual HTTP interaction with the UGS. So I havent tried manually calling it (client usage is blocked)

#

AccountService is configured as a singleton in the ModuleConfig

wraith zodiac
#

Hi, could you share the DI registration code?

#

It could also potentially be that your account service can't be initialized: worth checking that it has a single constructor with only parameters that can be resolved with DI

viral depot
#
using Microsoft.Extensions.DependencyInjection;
using Server.Accounts;
using Server.Rewards;
using Unity.Services.CloudCode.Apis;
using Unity.Services.CloudCode.Core;

namespace Server.Config;

public class ModuleConfig : ICloudCodeSetup
{
    public void Setup(ICloudCodeConfig config)
    {
        config.Dependencies.AddSingleton(GameApiClient.Create());
        config.Dependencies.AddSingleton(PushClient.Create());
        config.Dependencies.AddSingleton<IAccountService, AccountService>();
        config.Dependencies.AddSingleton<IRewardsService, RewardsService>();
    }
}
#

These are the constructor and configs

#

(this service is a mockup for now)

#

Is the push message API a standard feature in the Cloud Code? maybe it cant be initialized if I need to enable it for the project?

#

But you are suggesting I still have an initialization issue but this time it causes an unexpected error

#

This is the trigger file

wraith zodiac
#

DI setup looks fine to me. What version of the logging and DI packages do you have installed?

viral depot
#

I guess you are asking for these?

#

Using Unity 6 btw if it means anything..

wraith zodiac
#

Was the earlier 422 error resolved before this 500 started coming up? Is there a 2nd constructor in the AccountController class?

I think the best approach to would be to start from a simpler solution that's known to work, then add the dependencies back in 1 by 1 until you hit the issue. Hopefully that will let us isolate exactly where the problem is occurring.

Alternatively, if you send me your code (via PM) I can have a go at debugging it

viral depot
#

I reconfigured and went through the DI setup to solve this 422, and immediately after the change the 500 started coming up.
I dont mind sending it, would you like to receive the accountService class? with the controller?
anything else?

#

Just to clarify -

the specific function that is suppose to run in that API had worked before exacly as written.
When it was in the controller itself.

#

It was like that before (logger was injected in constructor tho)

#

Seems to work fine

#

Important update -

when removing the IPushClient from the constructor and config it is working!

#

(With AccountService layout)

#

Adding back -

still works

#

Adding it back to the constructor -

    public AccountService(ILogger<AccountService> logger, IRewardsService rewardsService, IGameApiClient gameApiClient, IPushClient pushClient)
    {
        _logger = logger;
        _rewardsService = rewardsService;
        _gameApiClient = gameApiClient;
        _pushClient = pushClient;
    }
#

makes it fail - 500

#

To summarize:

injecting IPushClient to a working service will return 500 error on a trigger function
when the config is config.Dependencies.AddSingleton(PushClient.Create());

#

(In my case at least)

#

Let me know if I am not using the correct interface/class for the message client.
And thank you for your time and help by the way! ๐Ÿ™‚

wraith zodiac
#

Aha! PushClient.Create() returns a PushClient not an IPushClient which is an unfortunate bit of inconsistency on our part. You'll need to register it with the interface explicitly, like this: config.Dependencies.AddSingleton<IPushClient>(PushClient.Create());

viral depot
#

But config.Dependencies.AddSingleton(GameApiClient.Create()); do make IGameAPIClient right?

#

I get it now

#

But the most troubling thing here, is the lack of logging on a configuration error.
It is really scary for us to run 'serverless' when this specific issue is suddenly a generic server error I cannot debug.

#

I do appricate your quick response, but I cannot count I will have VIP treatment like today in an everyday scenario ๐Ÿฅฒ

#

(I will let you know in a few moments if it solved the issue)

wraith zodiac
#

I agree on the lack of logging, not sure why it's not being properly handled in this instance. I'll investigate and get it fixed as soon as I can - we dread 500s as much as you do.

viral depot
#

It works now, thank you so much for your time!

viral depot
#

@mossy parrot as well ๐Ÿ™‚