Hi Team,
We all have been using Code Generators like Glass Mapper for our applications, Today in this post we will see the error which comes when you run leprechaun against XM Cloud starter repository, Steps for setting up leprechaun which are universal step & there is nothing major and very well documented at Leprechaun, So we will not discuss those step, You can easily configure it from the leprehaun site.
Leprechaun is a universal, open API for code generation from Rainbow serialized or Sitecore serialized Sitecore templates. Leprechaun uses state-of-the-art Roslyn code generation technology instead of T4 templates for speedy generation that doesn't require Visual Studio.
(Taken from https://github.com/blipson89/Leprechaun)
Leprechaun is very well documented, so i will not talk much about it But i will share some info where we were blocked for more than a week for which there was nothing available on the internet and those information i will share so you do not end up in the same issue
Scenario
We have used leprechaun for our couple of projects, and over there we had no major issues and it all worked fine for us (They were not on XM cloud Sxastarter repository, They were all on-prem XM), But recently we run into an issue for XM Cloud based code based, were we kept getting an exception from leprechaun "Leprechaun command exited with code 1"
I did so many changes to my configurations & also my leprechaun file to find out where could be the issue, but i was no where, it was always giving me this error, Steps i followed were
1) I changed my leprechaun to point to some wrong path of module.json in <configuration> node where we give path to module.json, there was no error and it all went and gave me proper messages back saying, there was no module found for which it can generate the code.
2) I also changed different code generation file, giving all of those at once and also tied giving them one by one by it was giving same error as "Exited with Code 1"
3) I tried switching to diagnosed modes in visual studio from tools->Options and in that Projects & solutions-> Build And Run and on right hand side, select "MSBuild project build output verbosity" to "Diagnostic" thinking that it might give something, but no luck, same error.
4) Uninstalled & install leprechaun again, but no luck
5) I compared with my on-prem projects with my XM Cloud and lepreachaun configurations were same and identical.
6) I tried it with simplest of the template thinking may be it could be templates causing issue, but same error.
7) Sometimes if you download the code generation files, they are generally blocked by default, so i also double checked that they are unblocked and have proper access, all good but same error.
With no clue, i reached out to leprechaun mentioning the behavior and thank you to ben lipson for getting on a call for this, and in our first call there was no clue, he was also surprised why there is no details of error and why its not working
Final Solution & Steps
ben lipson and i remained in touch for next couple of days to figure out the issue, He update the nuget with some more logs via which we can figure out the issue, i updated my leprechaun with that and it worked, we got some error like following
We were more interested in the error where it says "Endpoint dev was missing Authority (STS/Identity Server/AAD tenant URL) System.AggregateException"
This is where i felt it's something to do with the configuration either in leprechaun or on code, now ben lipson put more light on this where he mentioned about following code getting executed from leprechaun
The code in leprechaun at Leprechaun/ModuleConfigurationReader.cs at main · blipson89/Leprechaun (github.com)
That
call is to Sitecore.DevEx.Configuration.FilesystemConfigurationManager,
which resolves the sitecore.json file and calls Validate(). It's the
Validate that's failing, indicating something is wrong with the Sitecore
configuration.
So we looked into validate() method and that error was getting thrown from that code
Now, because it was mentioning DEV end point and it uses sitecore.json file, I recollect that there is only one file where end points are mentioned and that is user.json file
So, i opened up user.json file and tried to observe it and with my surprise, authority which the error is mentioning was mentioned only in "XmCloud" ref and for all other environment like "dev", "local" there was no authority url mentioned, see below
Now, this user.json file is created automatically and we do not change it manually, and it is not committed to source control too
But i just changed all the environment "dev", "local" and where ever the authority was not present and gave the value "https://auth.sitecorecloud.io/", Now i just tried to run the laprechaun again and i was so happy to see that it generated the model successfully and "exited with code 1" error was no more there and models got successfully created
Conclusion
I still have not figured out why my user.json do not have the authority url in all environment, but putting it to the above values works just fine
I reached out to sitecore too because,
The problem is that the command "dotnet sitecore cloud environment connect" does not require an authority to be passed, because the cloud plugin will assume that the authority is auth.sitecorecloud.io if it's blank.
However, Leprechaun doesn't use the cloud plugin, because it doesn't actually need to connect to Sitecore
Leprechaun isn't connecting to xm cloud. It's just using the devex API to find the yaml files. However, the devex api calls Validate, which might detected a problem with your user.json file, despite not actually needing to use it, and that is where i have reached out to sitecore
My other colleagues also facing the same issue and they also do not have authority in their user.json file, i am not sure why, All of they do not have it, so not sure what is the permanent solution to this, because we all are using standard sitecore xm cloud documentation located at https://doc.sitecore.com/xmc/en/developers/xm-cloud/walkthrough--setting-up-your-full-stack-xm-cloud-local-development-environment.html and the commands given there.
ben lipson will be changing the leprechaun code and releasing a new version which will output more error where it will mention the exact issue, which it is not outputting right now, so by looking it at it we can do the needed change, but the solution is to add "authority" url to all the environment if not present and run the leprechaun afterwards.
Note: This issue exists only in sxastarter repository because it contains multiple end points in user.json file.
Comments
Post a Comment