flatpak icon indicating copy to clipboard operation
flatpak copied to clipboard

[Bug]: "Locale not supported by C library" leading to "flatpak-spawn: Invalid byte sequence in conversion input"

Open espadrine opened this issue 2 years ago • 8 comments

Checklist

  • [X] I agree to follow the Code of Conduct that this project adheres to.
  • [X] I have searched the issue tracker for a bug that matches the one I want to file, without success.
  • [X] If this is an issue with a particular app, I have tried filing it in the appropriate issue tracker for the app (e.g. under https://github.com/flathub/) and determined that it is an issue with Flatpak itself.
  • [X] This issue is not a report of a security vulnerability (see here if you need to report a security issue).

Flatpak version

1.12.7

What Linux distribution are you using?

Ubuntu

Linux distribution version

22.04.1

What architecture are you using?

x86_64

How to reproduce

  1. Download Foliate from KDE Discover application (a Flatpak by default).
  2. Remove any export PS1='$ ' in ~/.bashrc etc; using instead PS1='$ ' (without the export) is fine, and will be used by the terminal, but will also reproduce the error. Ensure that the variable is not exported by checking that env | grep PS1 returns nothing.
  3. In a terminal, run flatpak run --branch=stable --arch=x86_64 --command=com.github.johnfactotum.Foliate --file-forwarding com.github.johnfactotum.Foliate @@u `pwd`/seriouscryptography.epub @@. You may replace seriouscryptography.epub with whichever epub file you have in the current directory. (The behaviour is consistent from within Konsole, Alacritty, and from simply opening an epub from Dolphin.)

Expected Behavior

The epub loads correctly. Example successful log:

(com.github.johnfactotum.Foliate:2): Gtk-WARNING **: 18:26:58.290: Locale not supported by C library.
	Using the fallback 'C' locale.
Portal call failed: Failed to start command: Failed to execute child process ?dict? (No such file or directory)
Portal call failed: Failed to start command: Failed to execute child process ?sdcv? (No such file or directory)

(process:2): Gtk-WARNING **: 18:26:59.122: Locale not supported by C library.
	Using the fallback 'C' locale.
Failed to create /home/tyl/.var/app/com.github.johnfactotum.Foliate/cache for shader cache (No such file or directory)---disabling.

(com.github.johnfactotum.Foliate:2): Gjs-WARNING **: 18:27:01.657: Unhandled promise rejection. To suppress this warning, add an error handler to your promise chain with .catch() or a try-catch block around your await expression. Stack trace of the failed promise:
  main@resource:///com/github/johnfactotum/Foliate/js/main.js:478:24
  run@resource:///org/gnome/gjs/modules/script/package.js:206:19
  @/app/bin/com.github.johnfactotum.Foliate:9:17

Actual Behavior

The app spins forever, indicating a crash. The log indicates a flatpak-spawn error.

Example failed log:

(com.github.johnfactotum.Foliate:2): Gtk-WARNING **: 18:25:49.067: Locale not supported by C library.
	Using the fallback 'C' locale.
Portal call failed: Failed to start command: Failed to execute child process ?dict? (No such file or directory)
Portal call failed: Failed to start command: Failed to execute child process ?sdcv? (No such file or directory)
flatpak-spawn: Invalid byte sequence in conversion input
Try "flatpak-spawn --help" for more information.

Additional Information

Successful workaround (used to show the expected behaviour) include setting $PS1 as with the following command:

PS1= flatpak run --branch=stable --arch=x86_64 --command=com.github.johnfactotum.Foliate --file-forwarding com.github.johnfactotum.Foliate @@u `pwd`/seriouscryptography.epub @@

or exporting $PS1 in .bashrc or the equivalent configuration file (although that will not work when opening from Dolphin: in that case, set the Exec entry in ~/.local/share/applications/com.github.johnfactotum.Foliate.desktop as Exec=env PS1= /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=com.github.johnfactotum.Foliate --file-forwarding com.github.johnfactotum.Foliate @@u %U @@, or by right-clicking on the menu, clicking "Edit Applications", selecting Foliate, updating the field for environment variables, and saving).

espadrine avatar Oct 21 '23 17:10 espadrine

Gtk-WARNING **: 18:26:58.290: Locale not supported by C library

This is the root cause of this issue. What are your locale environment variables set to? (LANG, LANGUAGE and anything starting with LC_ - you might find env|grep '^L' useful)

Whatever your locale is set to, either you don't have the corresponding Flatpak runtime extension installed (generally Flatpak should do this automatically, but perhaps for whatever reason it didn't), or there is no such runtime extension available, or the glibc used by the Flatpak app doesn't support that locale for whatever other reason.

glibc responds to this by falling back to the C locale, which treats all non-ASCII bytes as an error. This conflicts with Flatpak setting the shell prompt PS1 to a value that includes the UTF-8 emoji for a package (cardboard box), to indicate you are inside a Flatpak environment if you use an interactive shell there.

Forcing a different value for PS1 works around this by making all your environment variables be ASCII.

See also https://github.com/flatpak/flatpak-xdg-utils/pull/65, which attempts to address this from the flatpak-spawn side, but is unfortunately not fully correct either.

smcv avatar Oct 23 '23 10:10 smcv

Ah, this is an unexpected link to $PS1 indeed! How could I check whether the right Flatpak runtime extension is installed?

My LC-related environment variables are below, and I believe they are set from KDE UI settings. I target UTF-8 everywhere, but if glibc falls back to ASCII even in this case, perhaps it needs a more flexible UTF-8 check.

LANG=en_US.UTF-8
LANGUAGE=en
LC_ADDRESS=fr_FR.UTF-8
LC_NAME=fr_FR.UTF-8
LC_MONETARY=en_150.UTF-8
LC_PAPER=fr_FR.UTF-8
LC_IDENTIFICATION=fr_FR.UTF-8
LC_TELEPHONE=fr_FR.UTF-8
LC_MEASUREMENT=fr_FR.UTF-8
LC_TIME=en_150.UTF-8
LC_NUMERIC=en_US.UTF-8

espadrine avatar Oct 28 '23 17:10 espadrine

What is en_150? I am not aware of 150 being a country code that is supported by glibc.

Locale names normally look like en_US.UTF-8 ("English as spoken in the USA, with text encoded in UTF-8") or sr_RS@latin ("Serbian as spoken in Serbia, written using the Latin alphabet").

smcv avatar Oct 30 '23 13:10 smcv

How could I check whether the right Flatpak runtime extension is installed?

If I understand correctly, en_US.UTF-8 should be built-in, without any extensions, but fr_FR.UTF-8 will require the fr subset of the locale extension for whatever runtime your app uses. For instance, if it uses org.gnome.Platform/x86_64/45, the corresponding locale extension is org.gnome.Platform.Locale/x86_64/45.

Locale extensions don't appear in flatpak list by default, but can be seen in the output of flatpak list --all.

Locale extensions use a mechanism that only installs a subset of the extension, corresponding to the locales that are listed in your language settings. I don't know of an easy way to list what subset you have installed (a maintainer who knows the package-management side of Flatpak better would be able to say more).

smcv avatar Oct 30 '23 13:10 smcv

ICU Locale “English (Europe)” (en_150)

https://www.localeplanet.com/icu/en-150/index.html

Sorry for the bump, was looking for a way to make Epiphany (Web) run, it also crashes on my system.

~ $ localectl
System Locale: LANG=en_US.UTF-8
               LANGUAGE=en_US
               LC_NUMERIC=pt_BR.UTF-8
               LC_TIME=pt_BR.UTF-8
               LC_MONETARY=pt_BR.UTF-8
               LC_PAPER=pt_BR.UTF-8
               LC_NAME=pt_BR.UTF-8
               LC_ADDRESS=pt_BR.UTF-8
               LC_TELEPHONE=pt_BR.UTF-8
               LC_MEASUREMENT=pt_BR.UTF-8
               LC_IDENTIFICATION=pt_BR.UTF-8
    VC Keymap: us-intl
   X11 Layout: us
    X11 Model: microsoftpro
  X11 Variant: intl
  X11 Options: terminate:ctrl_alt_bksp

Even if I run any of these an reinstall:

flatpak --user config --set languages 'en'
flatpak --user config --set languages 'en;pt'

Epiphany just crashes upon startup with the same error as this issue title

rodrigopedra avatar Mar 10 '24 10:03 rodrigopedra

One more thing: installing epiphany from openSUSE packages works fine. It just misbehaves when running as a flatpak

rodrigopedra avatar Mar 10 '24 10:03 rodrigopedra

@rodrigopedra

Is Epiphany installed in the user or system installation? flatpak config settings only apply to the specified installation since they control the installation of locale subsets. In theory, you shouldn't need to change anything there because flatpak will detect the system locale(s).

Please share the flatpak config output for the appropriate installation (i.e. with or without --user), as well as flatpak run --command=locale org.gnome.Epiphany.

chrisawi avatar Mar 10 '24 21:03 chrisawi

As for the original issue, en_150 is not supported by glibc. I don't see any evidence that Ubuntu has patched that in either. You need to use a supported locale like en_DK.UTF-8 or en_IE.UTF-8.

chrisawi avatar Mar 10 '24 21:03 chrisawi