Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 577862

Summary: sys-apps/portage: emerge UnicodeDecodeError raised from locale.format() via portage.localization.localized_size
Product: Portage Development Reporter: Zac Medico <zmedico>
Component: Core - Interface (emerge)Assignee: Portage team <dev-portage>
Status: RESOLVED FIXED    
Severity: normal CC: info
Priority: Normal Keywords: InVCS
Version: 2.2   
Hardware: All   
OS: All   
URL: https://forums.gentoo.org/viewtopic-t-1040978.html
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 573774    

Description Zac Medico gentoo-dev 2016-03-20 19:53:55 UTC
Traceback (most recent call last):
  File "/usr/lib/python-exec/python3.4/emerge", line 50, in <module>
    retval = emerge_main()
  File "/usr/lib/python3.4/site-packages/_emerge/main.py", line 1174, in emerge_main
    return run_action(emerge_config)
  File "/usr/lib/python3.4/site-packages/_emerge/actions.py", line 3231, in run_action
    emerge_config.args, spinner)
  File "/usr/lib/python3.4/site-packages/_emerge/actions.py", line 356, in action_build
    favorites=favorites)
  File "/usr/lib/python3.4/site-packages/_emerge/depgraph.py", line 7967, in display
    return display(self, mylist, favorites, verbosity)
  File "/usr/lib/python3.4/site-packages/_emerge/resolver/output.py", line 861, in __call__
    self.verbose_size(pkg, None, pkg_info)
  File "/usr/lib/python3.4/site-packages/_emerge/resolver/output.py", line 334, in verbose_size
    self.verboseadd += localized_size(mysize)
  File "/usr/lib/python3.4/site-packages/portage/localization.py", line 41, in localized_size
    formatted_num = locale.format('%d', num_kib, grouping=True)
  File "/usr/lib/python3.4/locale.py", line 195, in format
    return _format(percent, value, grouping, monetary, *additional)
  File "/usr/lib/python3.4/locale.py", line 216, in _format
    formatted, seps = _group(formatted, monetary=monetary)
  File "/usr/lib/python3.4/locale.py", line 140, in _group
    conv = localeconv()
  File "/usr/lib/python3.4/locale.py", line 111, in localeconv
    d = _localeconv()
UnicodeDecodeError: 'locale' codec can't decode byte 0xc2 in position 0: Invalid or incomplete multibyte or wide character
Comment 1 Zac Medico gentoo-dev 2016-03-20 19:56:57 UTC
It must be a python bug or something wrong with the locale.

We'll just have to handle the UnicodeDecodeError inside that portage.localization.localized_size function, and just fallback to some kind of dumb formatting.
Comment 2 Zac Medico gentoo-dev 2016-03-21 04:00:23 UTC
Looking at Modules/_localemodule.c in the python source tree, it must be failing to decode the locale data in the PyLocale_localeconv function where it calls this code:

#define RESULT_STRING(s)\
    do { \
        x = PyUnicode_DecodeLocale(l->s, NULL); \
        RESULT(#s, x); \
    } while (0)

The PyUnicode_DecodeLocale function is defined in Objects/unicodeobject.c, and it is capable of raising UnicodeDecodeError.

So, I think our best course of action is to handle the UnicodeDecodeError as suggested in comment #1.
Comment 3 Zac Medico gentoo-dev 2016-03-21 04:17:12 UTC
There's a patch in the following branch:

https://github.com/zmedico/portage/tree/bug_577862

It can be applied as follows:

mkdir -p /etc/portage/patches/sys-apps/portage
wget -O /etc/portage/patches/sys-apps/portage/bug_577862.patch \
https://github.com/zmedico/portage/commit/327834be018781c7e6da9734140f74e6d4e23c6a.patch
emerge -1 portage

I've posted the patch for review here:

https://archives.gentoo.org/gentoo-portage-dev/message/ec52ee334e5336f747720df007046a0f
Comment 5 Zac Medico gentoo-dev 2017-08-11 20:04:59 UTC
Fixed in 2.3.0.