New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setlocale(): Specified locale name is too long #193
Comments
Thanks @ewallah for raising this issue. Some days ago, I stumbled upon the same issue in my Behat tests which broke after adopting the latest proposed changes of moodle-plugin-ci to my Github actions configuration. I asked about this issue in Moodle dev chat, trying to figure out how this can be solved and if this error might be related to MDL-74512, and @stronk7 and @andrewnicols answered helpfully, but I couldn't resolve the issue after all. Now I noticed that you have already reported this issue here and have proposed a workaround. This helped me to get my tests up and running again. Thanks for that! In my case, the error was thrown in the Behat step I also noticed that the error is only thrown if I run Github actions on ubuntu-22.04 as it's recommended now. If I run the same Github actions configuration file on ubuntu-18.04, the tests pass without any problems. I assume that the default locale might have changed between the Ubuntu versions, but I am unsure how and where to fix this properly and sustainably for moodle-plugin-ci now. Cheers, |
I have this sudo locale-gen en_AU.UTF-8 in the plugin initialise step -
https://github.com/gjb2048/moodle-theme_foundation/blob/master/.github/workflows/ci.yml#L70
- as without it, the PHPUnit tests fail to run. Might help here?
|
But, that has been recommended since the very beginning of the GHA integration, isn't it? https://github.com/moodlehq/moodle-plugin-ci/blob/master/gha.dist.yml#L57 I'm not sure we need to add anything else. Or are you saying that, no matter that line, tests continue failing? Ciao :-) |
Another issue is that the 4.2 lang packs... don't exist yet... so if your tests include any test trying to import lang-packs in master (4.2dev), they will fail. Not sure if that's your problem or no. References (we have them disabled in CIs till the new lang packs are available):
Ciao :-) |
Thanks, @gjb2048 . But I have this line in my config as it's recommended (see https://github.com/moodle-an-hochschulen/moodle-local_navbarplus/blob/master/.github/workflows/moodle-plugin-ci.yml#L56) and tests are failing on ubuntu-22.04
No, that's not my issue. My tests are targetting Moodle 4.0 Stable. |
@abias and @stronk7 Ah ok :). Not twigged that. I run Behat tests on Collapsed Topics -> https://github.com/gjb2048/moodle-format_topcoll/blob/master/.github/workflows/ci.yml - and that works on ubuntu-22.04 or at least did on the last run. Has something changed? |
Hi @gjb2048, right now I don't know much. I also reran 1-2h ago all the local_codechecker own tests to check if this problem was something global: https://github.com/moodlehq/moodle-local_codechecker/actions/runs/3558869848 But they passed ok, so it seems that the problem is related with behat steps trying to import a language. That's the reason I warned about the inexistent yet 4.2 language packages. And then @abias confirmed that it happens to him not with 4.2, but with older branches. So all we know right now is:
Let's see if we can trace this down... |
@abias Given the stack trace and looking at the code (how the called get_list_of_translations() string_manager method seems to work), I don't think its to do with the environment but rather the actual Moodle files etc. Do you have any custom plugins with different languages in their lang folders? |
Aha, @abias , now I remember the previous discussion! And remember that I looked to this: https://github.com/stronk7/moodle/blob/master/admin/tool/langimport/classes/locale.php#L62 And I only could imagine some connectivity glitch being the problem, somehow corrupting the In the other side, I've been able to reproduce it now (@ GHA): https://github.com/stronk7/moodle-local_navbarplus/actions/runs/3676900419 So now I'm going to try to:
Wish me luck! Ciao :-) PS: I still cannot imagine how setting LC_ALL helps, maybe it does by setting back the original LC_ALL that with old Ubuntus was set and not with 22.04... in any case, that's after my 1-2 above. I want to check first if the problem happens because of some exact language and wrong locale within its configuration. |
Ok, so the problem doesn't happen when trying to set the locale from the lang file (line #65). It happens 3 lines below, when trying to restitute the original ( So, then the line suggested by @ewallah makes sense if it happens that Ubuntu 22.04 comes with it undefined, and older versions had it defined. Going to check that now... |
Wow, this is a real surprise. I just modified the workflow to output both:
And, or I'm missing something... or the default locale ( Run: https://github.com/stronk7/moodle-local_navbarplus/actions/runs/3677316897 So, how is it possible that 22.04 is failing and 20.04 is passing? They use exactly the same default locale, that for sure is installed in the system. I cannot understand which the difference can be. Note that I'm starting to imagine that we can workaround that from within moodle-plugin-ci, by setting the env variable (LANG or LC_ALL) before invoking behat, so this seems to be fixable. The problem is that I don't understand why that fix is needed, and I don't like to apply for mysterious fixes. I'm going to debug a little bit more against custom moodle to see if there is any difference between the tests above (returning Ciao :-) |
I've added some debugging to the tool_langimport\locale::check_locale_availability() method. And, then, just visited the Language import utility page. And testing it locally (Mac)... I get this (only English is installed by default:
So, when processing the "en" lang pack, first it fetches $currentlocale (that is a log string separated by slashes), then tries to set the locale to the lang pack one (en_AU.UTF-8) and does is successfully. And, finally, it sets the locale back to the $currentlocale fetched at the beginning, and that operation is successful too. It would be great if you can share here what do you get in apache logs with your Ubuntus or any other linux flavour, just to be able to compare stuff. Ciao :-) |
Hi @stronk7, No idea if this helps, but I'm running a custom WAMP on Windows 10 and get:
So possibly interesting for comparison? I have a Ubuntu VM machine so if I can get it working... Cheers, Gareth |
Yeah, that's correct too. The code doesn't fail for you. In the Mac I was surprised about the "/" (slashed) formatting, but it worked ok when using it to set back the original locale. In your windows, it's better formatted, with semi-colon separated information. And also worked ok when using it to set back the original locale. Note that if any set_locale fails we should see a 0/empty (false) in some of the logged lines. Let's see with Ubuntu (or any other linux). |
Thanks to @sarjona I got it run against Ubuntu 20.04:
It also worked ok, no error at all and all the setlocale() calls returned information. |
Hi @stronk7, Fired up a Ubuntu 22.04 and get:
But I don't think the sever is quite right! -> But I get:
Cheers, Gareth |
I think you're missing the en_AU.UTF-8 locale and it's warning you about that, in fact the In any case, you did not get the "Specified locale name is too long" error/exception. And it's 22.04! |
@stronk7 Thanks, I found https://askubuntu.com/questions/76013/how-do-i-add-locale-to-ubuntu-server before I saw your reply! So after reboot the error goes away and:
and the server is:
G |
Thanks @gjb2048 ! So it's working ok on your local Ubuntu 22.04 too. Ok, I'm going to do some more tests against GHA, trying to output the web server logs containing the debugging as part of the workflow. Let's see if we find why 22.04 on GHA makes any difference! |
No worries @stronk7 and just in case:
G |
Ok, by hacking a little bit moodle-plugin-ci and pointing to it from [my fork of moodle-local_navbarplus... I've been able to get the web server logs in output. See: And, certainly... the set_locale() call switching back to the original local it failing there. Although the original one looks really correct (exactly the same than the ones reported here for 20.04 and 22.04). So it continues being a good mystery.
Now that I've access to the web server logs... I'm going to try with 20.04 to be able to compare results... Let's see, this is being fun! Ciao :-) |
Uhm... interesting.... it seems that locale max length is 255 (and the failing logs above are 268 if I've counted them correctly), have found various reports out there. Example: horde/horde@13d2342#diff-43cdf63cea18bc549d232f55b13b3b14536151d45f8e771a8e1e398762456d34R141-R148 Ok, going to compare with 20.04 and then decide if we have to apply for something similar... |
And just for reference, because we'll need that... in Macs (that is a BSD unix), the "slashed" locales are perfectly ok. Each one corresponds to one of six LC variables. Fixed. Source: https://man.openbsd.org/setlocale.3#RETURN_VALUES
So one less mystery... now let's see how the multi-ubuntu tests end... https://github.com/stronk7/moodle-local_navbarplus/actions/runs/3684814565 Back in a few hours... ciao :-) |
Ok, so from the run commented above:
And the differences are because some of the elements have "C" in 18_04, but "C.UTF-8" in 20_04 and 24_04, leading to > 255 chars. Windows "may" be exposed to the same problem (theoretically), if there is some long-enough locale which total length becomes > 255. Macs will be hardy affected by this, because it always returns a fixed 6-elements list (as explained above) and no combination of 6 locales (42 chars each, they should be) can lead to > 255. So, conclusions:
I'm going to leave this open till the issue in the tracker is fixed. Good we were able to find the root cause, yay! Ciao :-) |
@stronk7 - Kudos for going down the rabbit hole that far! |
The very first candidate branches have been put @ MDL-76666. They are passing ok under mac/win/linux and they cover the specific linux case. Also, I've modified my fork of navbarplus to point to those candidate branches, and it has passed ok, so far: https://github.com/stronk7/moodle-local_navbarplus/actions/runs/3693007313 So it's looking good, aiming to send it to PR soon (just a few more tests to run and done!) So I'm going to close this now, thanks all for your support, it made easier to find the root cause (plus, we all have learnt a lot more about those "$·/&%$&% locales) 😆 Ciao :-) |
Since a week I see these errors in GitHub Actions when I use language related functions in behat tests :
I suspect that the locale used in behat test is not en_AU.UTF-8 but the Ubuntu default.
A possible workaround for avoiding these errors is forcing en_AU.UTF-8 in your behat tests:
With these additional lines, my behat tests pass successfully.
The text was updated successfully, but these errors were encountered: