Skip to content

refactor: commands raise; cli.main is the sole error emitter - #117

Merged
DLANSAMA merged 3 commits into
mainfrom
refactor/aaa-pr8-error-path
Aug 13, 2026
Merged

refactor: commands raise; cli.main is the sole error emitter#117
DLANSAMA merged 3 commits into
mainfrom
refactor/aaa-pr8-error-path

Conversation

@DLANSAMA

Copy link
Copy Markdown
Owner

AAA stack 8/9. Stacked on #116.

Domain code raises BambuError / abort(..., extra=). cli.main is the only place that writes the --json error envelope (write_error_envelope). emit_json_error becomes a thin raise wrapper so leftover call sites do not emit-then-abort.

BambuError.extra / to_error_payload() carry machine-readable extras (failed_step, redacted source, extension, …) so job and tests can rebuild the envelope without reading stdout.

Stack: #110#111#112#113#114#115#116this → honesty

Domain handlers abort() with extra envelope keys on BambuError.
write_error_envelope is the only JSON error writer. Remaining
emit_json_error call sites raise via abort so they cannot emit twice.
Job reads the exception instead of the last-error global.
abort("") dropped the step, so plate download --json not-a-url emitted
an envelope without failed_step and the contract test failed.
emit_json_error now logs and records extras before raising, so download
URL validation still redacts credentials and names failed_step. URL
checks abort with a real message instead of "Command failed (exit N)".
RuntimeContext.printer() uses get_printer() when it is the installed
context so the one factory is the patch point.

Setup, preflight, and setup --migrate-access-code emit through Contract
objects. Domain commands no longer write JSON envelopes; tests inspect
BambuError extras and cli.main remains the sole stdout writer.
Base automatically changed from refactor/aaa-pr7-test-stubs to main August 13, 2026 04:12
@DLANSAMA
DLANSAMA force-pushed the refactor/aaa-pr8-error-path branch from 90f218f to 308345f Compare August 13, 2026 04:12
@DLANSAMA
DLANSAMA merged commit d32a0c6 into main Aug 13, 2026
6 of 12 checks passed
@DLANSAMA
DLANSAMA deleted the refactor/aaa-pr8-error-path branch August 13, 2026 04:21
DLANSAMA added a commit that referenced this pull request Aug 14, 2026
* refactor: printer factory, MQTT/FTPS hardening, coverage to 86

Continues the boundary/error-model arc (#117/#118).

Architecture:
- RuntimeContext.printer() now uses an injectable factory registered
  downward from bambu_cli.printer (set_printer_factory); context.py no
  longer imports printer. Removes the last check_layers ALLOWED edge
  (context -> printer); ALLOWED is now empty.

Correctness / resources:
- mqtt_session: lock _pending_payload/_command_issued across the paho
  network thread; cached-complete-snapshot fast path on silent pushall.
- mqtt_tls: drop global socket.setdefaulttimeout mutation; bound connect
  via client._connect_timeout; configurable, validated MQTTS port.
- mqtt_cmd/mqtt_print/mqtt_monitor: teardown in finally (fixes leak on
  the connect-exception path).
- ftps: close the socket if connect/login/prot_p fails.
- snapshot/slice: drop unreachable safe_log_error+abort tails after
  emit_json_error (now typed NoReturn); it already logs and raises.

Tests / CI:
- +40 targeted tests for the above error paths; raise CI cov floor
  83 -> 86 (measured 91.0% Linux). Stronger docs-coverage drift guard.
- Docs: api.md support matrix; SECURITY.md residuals marked accepted
  for 1.0; scoreboard refreshed.

* test: make preflight perms test platform-aware (Windows CI)

_file_permission_check returns None on win32 by design (POSIX mode bits
don't apply — see the Windows secret ACLs residual in SECURITY.md), so
the 0o644/0o600 assertions only hold off-Windows. Assert the None path
on win32 instead.

---------

Co-authored-by: DLANSAMA <258674612+DLANSAMA@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant