Buildstream crashes unhelpfully when ujson can't process a cache key
- Dominant language
- Python
- Stars
- 140
- Forks
- 45
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
[See original issue on GitLab](https://gitlab.com/BuildStream/buildstream/-/issues/1341)
In GitLab by [[Gitlab user @willsalmon]](https://gitlab.com/willsalmon) on Jun 16, 2020, 10:28
## Summary
[Edit/update] Buildstream plugins must supply a function called "get_unique_key", which returns an object that can be used to identify an element based on the config defined in its YAML. If the object is in a format that cannot be processed correctly, this can cause buildstream to crash when calculating the key.
There ought to be a clean failure, with a helpful error message. Instead we get a crash, and a traceback that doesn't immediately explain the problem. [End edit/update]
```
(venvbuildstream) [will[[Gitlab user @wsx280]](https://gitlab.com/wsx280) freedesktop-sdk]$ bst build flatpak-release.bst
[--:--:--][ ][ main:core activity ] START Build
[--:--:--][ ][ main:core activity ] START Loading elements
[00:00:02][ ][ main:core activity ] SUCCESS Loading elements
[--:--:--][ ][ main:core activity ] START Resolving elements
[00:00:00][ ][ main:core activity ] SUCCESS Resolving elements
[--:--:--][ ][ main:core activity ] START Initializing remote caches
[00:00:00][ ][ main:core activity ] SUCCESS Initializing remote caches
[--:--:--][ ][ main:core activity ] START Resolving cached state
[--:--:--][ ][ main:core activity ] START Terminating buildbox-casd
[00:00:01][ ][ main:core activity ] SUCCESS Terminating buildbox-casd
[--:--:--][ ][ main:core activity ] BUG is not JSON serializable
Traceback (most recent call last):
File "/home/will/projects/buildstream/venvbuildstream/bin/bst", line 8, in
sys.exit(cli())
File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/will/projects/buildstream/buildstream/src/buildstream/_frontend/cli.py", line 280, in override_main
original_main(self, args=args, prog_name=prog_name, complete_var=None, standalone_mode=standalone_mode, **extra)
File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/will/projects/buildstream/venvbuildstream/lib64/python3.7/site-packages/click/decorators.py", line 33, in new_func
return f(get_current_context().obj, *args, **kwargs)
File "/home/will/projects/buildstream/buildstream/src/buildstream/_frontend/cli.py", line 501, in build
app.stream.build(elements, selection=deps, ignore_junction_targets=ignore_junction_targets, remote=remote)
File "/home/will/projects/buildstream/buildstream/src/buildstream/_stream.py", line 282, in build
dynamic_plan=True,
File "/home/will/projects/buildstream/buildstream/src/buildstream/_stream.py", line 1266, in _load
self._pipeline.resolve_elements(self.targets)
File "/home/will/projects/buildstream/buildstream/src/buildstream/_pipeline.py", line 121, in resolve_elements
element._initialize_state()
File "/home/will/projects/buildstream/buildstream/src/buildstream/element.py", line 1184, in _initialize_state
self.__update_resolved_state()
File "/home/will/projects/buildstream/buildstream/src/buildstream/element.py", line 2330, in __update_resolved_state
self.__update_cache_keys()
File "/home/will/projects/buildstream/buildstream/src/buildstream/element.py", line 3006, in __update_cache_keys
self.__weak_cache_key = self._calculate_cache_key(dependencies)
File "/home/will/projects/buildstream/buildstream/src/buildstream/element.py", line 2104, in _calculate_cache_key
return _cachekey.generate_key(cache_key_dict)
File "/home/will/projects/buildstream/buildstream/src/buildstream/_cachekey.py", line 65, in generate_key
ustring = ujson.dumps(value, sort_keys=True, escape_forward_slashes=False).encode("utf-8")
TypeError: is not JSON serializable
(venvbuildstream) [will[[Gitlab user @wsx280]](https://gitlab.com/wsx280) freedesktop-sdk]$
```
## Steps to reproduce
Install bst at tag 1.93.4
install bst-plugins-experimental at `commit aa3c71568b0cdc537028e6ec389276bb79441f46 (HEAD -> master, origin/master, origin/HEAD)`
checkout Freedesktop-sdk at
```
commit 6eaed03f17ba70428c7beac6b8121f2da62aac7d (HEAD -> willsalmon/bst2-fv, origin/willsalmon/bst2-fv)
Author: William Salmon
Date: Wed May 13 16:07:47 2020 +0100
Use pip from bst-plugins-experimental
```
## What is the current bug behaviour?
[[Gitlab user @BenjaminSchubert]](https://gitlab.com/BenjaminSchubert) thinks this is a issue with the plugins repo, i dont understand why it works in CI `https://gitlab.com/freedesktop-sdk/freedesktop-sdk/-/jobs/593127809` with what i belive are the same versions.
But if the bug is in the plugins then bst should handle this failer cleanly
Contributor guide
Research direction
Start in src/buildstream/_cachekey.py at generate_key(), then trace its caller in src/buildstream/element.py through __update_cache_keys and _calculate_cache_key. Reproduce with the listed BuildStream, plugin, and freedesktop-sdk revisions, and confirm that an unprocessable cache-key value produces a clean, explanatory failure instead of the ujson TypeError traceback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100