Skip to content

Handle SSH access failure (exit 255) in is_dispatch_aware with actionable error#239

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-jhack-ssh-access-error
Draft

Handle SSH access failure (exit 255) in is_dispatch_aware with actionable error#239
Copilot wants to merge 2 commits intomainfrom
copilot/fix-jhack-ssh-access-error

Conversation

Copy link

Copilot AI commented Mar 17, 2026

In Juju 4+, SSH access is not configured by default. is_dispatch_aware calls juju ssh and only handled exit code 1 (file not found); exit code 255 (SSH connection failure) was re-raised as a raw CalledProcessError, producing a noisy, unhelpful traceback.

Changes

  • jhack/helpers.pyis_dispatch_aware: Catch CalledProcessError with returncode == 255 and raise a RuntimeError with a clear message and step-by-step instructions to add SSH keys to Juju.
RuntimeError: SSH access to 'hello-juju/0' failed (exit code 255).
SSH is not configured by default in Juju 4+.
To fix this, add your SSH key to Juju:
  1. If you don't have an SSH key yet: ssh-keygen -b 4096
  2. juju add-ssh-key "$(cat ~/.ssh/id_rsa.pub)"
Original prompt

This section details on the original issue you should resolve

<issue_title>Jhack exception if no SSH access to Juju unit (default in Juju 4+)</issue_title>
<issue_description>### Bug Description

Hi,

usage jhack on default Juju 4 deployment generates a complex trace due to lack of unit access (SSH is not configured by default).

To Reproduce

juju version # 4.0.1-genericlinux-amd64
juju add-model test
juju deploy hello-juju
jhack fire hello-juju/0 update-status
hello-juju/0 update-status
╭───────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /snap/jhack/601/lib/python3.12/site-packages/jhack/utils/simulate_event.py:570 in simulate_event                                                                                                                                                     │
│                                                                                                                                                                                                                                                      │
│   567 │   Especially useful in combination with jhack charm sync and/or debug-code/debug-hooks ╭───────────── locals ──────────────╮                                                                                                                 │
│   568 │   """                                                                                  │      check_name = None            │                                                                                                                 │
│   569 │   print(target, event)                                                                 │         dry_run = None            │                                                                                                                 │
│ ❱ 570 │   return _simulate_event(                                                              │    env_override = None            │                                                                                                                 │
│   571 │   │   target,                                                                          │           event = 'update-status' │                                                                                                                 │
│   572 │   │   event,                                                                           │           model = None            │                                                                                                                 │
│   573 │   │   relation_remote=relation_remote,                                                 │       notice_id = None            │                                                                                                                 │
│                                                                                                │        parallel = None            │                                                                                                                 │
│                                                                                                │     relation_id = None            │                                                                                                                 │
│                                                                                                │ relation_remote = None            │                                                                                                                 │
│                                                                                                │          secret = None            │                                                                                                                 │
│                                                                                                │     show_output = True            │                                                                                                                 │
│                                                                                                │          target = 'hello-juju/0'  │                                                                                                                 │
│                                                                                                ╰───────────────────────────────────╯                                                                                                                 │
│                                                                                                                                                                                                                                                      │
│ /...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes canonical/jhack#234

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

…rror message

Co-authored-by: PietroPasotti <6230162+PietroPasotti@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Jhack exception if no SSH access to Juju unit Handle SSH access failure (exit 255) in is_dispatch_aware with actionable error Mar 17, 2026
Copilot AI requested a review from PietroPasotti March 17, 2026 17:17
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.

2 participants