fix(ebuild): repair SyntaxError in dispatch.py and unify backend errors - #78
Open
prakhar7017 wants to merge 1 commit into
Open
Conversation
## Problem
`ebuild/build/dispatch.py` does not parse. `BackendDispatcher.configure()`
carries two `else:` clauses attached to the same `if` chain:
File "ebuild/build/dispatch.py", line 133
else:
^^^^
SyntaxError: invalid syntax
Every `ebuild` command that reaches the dispatcher imports this module, so
on master `ebuild build`, `ebuild configure` and `ebuild clean` all fail at
import, and pytest aborts collection with 2 errors before running anything.
The cause is a merge, not a typo. Two branches independently added an
unhandled-backend guard to `configure()` — one raising `ValueError` listing
`ALL_BACKENDS`, one raising `RuntimeError` with a ninja-specific hint. The
merge kept both bodies. Their two test suites survived as well and disagree:
`tests/ebuild/test_dispatch.py` expects `ValueError`, `tests/unit/test_dispatch.py`
expects `RuntimeError`.
Two further defects were preserved in the same chain:
- `configure()` listed `ninja` alongside make/kbuild as a silent no-op.
`ebuild build` routes `backend: ninja` with no `targets` into the
dispatcher (`commands.py`: `if resolved_backend != "ninja" or not
cfg.targets`), which has no ninja configure step. Returning quietly there
is the exact false-success the `RuntimeError` guard was written to stop.
- The `ValueError` message advertised `ALL_BACKENDS`, which contains
`ninja`, so rejecting `ninja` produced a message naming `ninja` as
supported.
## Fix
- Remove the duplicated `else:` and consolidate the two guards into one.
- Add `UnknownBackendError(ValueError, RuntimeError)`. Deriving from both
keeps each pre-existing caller contract intact rather than silently
dropping one, and it is load-bearing beyond the tests: `ebuild build`
handles this through `except RuntimeError`, so a plain `ValueError` would
reach the user as a traceback instead of a clean `exit 1`.
- Name the backends each step actually handles (`CONFIGURE_BACKENDS`,
`BUILD_BACKENDS`, `CLEAN_BACKENDS`) and report those in the message, so it
can no longer contradict the rejection. `clean` keeps `ninja`; it only
removes a build directory and needs no toolchain.
- Drop `ninja` from the `configure()` no-op branch so it raises, carrying the
actionable "requires 'targets' in build.yaml" hint.
Behaviour change: `BackendDispatcher.configure("ninja")` previously returned
None and now raises. Nothing in-tree relies on the old behaviour — the CLI
`configure` command routes ninja to `_configure_ninja_backend` before the
dispatcher is constructed.
## Testing
- `pytest tests/ebuild/test_dispatch.py tests/unit/test_dispatch.py` —
31 passed. Both previously-conflicting suites pass unmodified.
- Full suite: 196 passed, 1 skipped, 11 failed. All 11 failures are
pre-existing and unrelated (`_object_path` missing from `NinjaBackend`,
initramfs integration, build-failure output); they were present before
this change and are unaffected by it.
- End-to-end, a `build.yaml` with `backend: ninja` and no `targets`:
[error] Unknown build backend 'ninja'. BackendDispatcher can
configure: cargo, cmake, kbuild, make, meson. ebuild's own ninja
backend is invoked directly rather than through BackendDispatcher,
and requires 'targets' in build.yaml -- add targets or choose
another backend.
EXIT=1
Clean message, correct exit code, no traceback.
- Six regression tests added covering the dual-inheritance contract, the
ninja rejection, the actionable hint, the non-contradictory backend list,
`clean("ninja")` still working, and cargo/make/kbuild remaining no-ops.
Signed-off-by: Prakhar Maheshwari <mpr@stordocktech.com>
Signed-off-by: Prakhar Maheshwari <prakharmaheshwari96@gmail.com>
prakhar7017
requested review from
hshanmug12,
maheshmunnangi and
srpatcha
as code owners
August 30, 2026 12:07
This was referenced Aug 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a syntax error in
ebuild/build/dispatch.pycaused by duplicateelse:clauses inBackendDispatcher.configure().The merge conflict left two different unknown-backend guards in the same
ifchain, causingebuild build,ebuild configure, andebuild cleanto fail during import.Changes
else:and consolidated the backend validation logic.UnknownBackendError, inheriting from bothValueErrorandRuntimeError, to preserve the existing caller contracts.CONFIGURE_BACKENDSBUILD_BACKENDSCLEAN_BACKENDSninjafrom the configure no-op path so unsupportedninjaconfiguration fails with an actionable error.ninjasupported forclean, where no toolchain is required.ValueError/RuntimeErrorinheritanceninjarejection during configureclean("ninja")continuing to workcargo,make, andkbuildno-op behaviorTesting
Targeted tests