Skip to content

Invalid format specifier crash #9

@Strangenoise

Description

@Strangenoise

Hi BigRoy, thanks for all your work on acre and OpenPype.
I just faced a small and peculiar issue and whished to inform you about it.

Context
I'm deploying rez in my studio and we use OpenPype.
I modified OpenPype to be a rez package and also be able to launch rez packages (instead of applications).
So I've got an acre rez package.

On windows 10, everything is ok.
On linux (Pop!_OS 22.04 LTS), acre crashes when trying to format REZ_STORED_PROMPT_SH environment variable.

With this env var containing: 'REZ_STORED_PROMPT_SH': '\\[\\e]0;\\u@\\h: \\w\\a\\]${debian_chroot:+($debian_chroot)}\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ .
Note that's an env var generated by rez, not one that I control directly.

Traceback

Traceback (most recent call last):
  File "/home/admin/Documents/rez/packages/build/openpype/4.0.0/python/start.py", line 1208, in <module>
    boot()
  File "/home/admin/Documents/rez/packages/build/openpype/4.0.0/python/start.py", line 1106, in boot
    set_openpype_global_environments()
  File "/home/admin/Documents/rez/packages/build/openpype/4.0.0/python/start.py", line 309, in set_openpype_global_environments
    env = acre.compute(merged_env, cleanup=False)
  File "/home/admin/Documents/rez/packages/build/acre/0.0.1/python/acre/core.py", line 71, in compute
    env[key] = lib.partial_format(env[key], data=data)
  File "/home/admin/Documents/rez/packages/build/acre/0.0.1/python/acre/lib.py", line 45, in partial_format
    return formatter.vformat(s, (), mapping)
  File "/home/admin/Documents/rez/packages/build/python/3.10.12/platform-linux/arch-x86_64/os-Pop-22.04/python/lib/string.py", line 165, in vformat
    result, _ = self._vformat(format_string, args, kwargs, used_args, 2)
  File "/home/admin/Documents/rez/packages/build/python/3.10.12/platform-linux/arch-x86_64/os-Pop-22.04/python/lib/string.py", line 218, in _vformat
    result.append(self.format_field(obj, format_spec))
  File "/home/admin/Documents/rez/packages/build/python/3.10.12/platform-linux/arch-x86_64/os-Pop-22.04/python/lib/string.py", line 235, in format_field
    return format(value, format_spec)
ValueError: Invalid format specifier

Solution proposal
Keep data unformated when they can't be.
In core.py (67:74):

    for key in reversed(result.sorted):
        if key in env:
            data = env.copy()
            data.pop(key)    # format without itself
            try:
                env[key] = lib.partial_format(env[key], data=data)
            except ValueError:
                env[key] = data[key]

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions