canonical / canonical/craft-cli

CraftError messages with new lines render inconsistently

Open
#269 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
16
Forks
27
Avg merge
1d 22h
Merged PRs (30d)
10

Description

### Bug Description

If the `message` field in a `CraftError` contains a new line, craft-cli appears to append whitespace, which causes the appearance of a new line between the `message` and `resolution` sections.

Note that I cannot use the `details` field because `details` isn't visible at the default `brief` verbosity level.

### To Reproduce

```diff
diff --git a/examples.py b/examples.py
index c842a1a..c7fe76e 100755
--- a/examples.py
+++ b/examples.py
def example_10():
@@ -513,6 +516,15 @@ def example_30():
time.sleep(0.001)

+def example_31():
+ """Show an error."""
+ path = "/dev/null"
+ raise CraftError(
+ message="Remote build does not support building multiple snaps on the same architecture:\n - Building on 'amd64' will create snaps for 'amd64' and 'riscv64'.",
+ resolution="this is the resolution",
+ )
+
+
# -- end of test cases

if len(sys.argv) < 2:
```

### part yaml

_No response_

### Relevant log output

See the attached pictures. The same photo is highlighted to show what appears to be extraneous whitespace.

![Screenshot_20240827_164350](https://github.com/user-attachments/assets/0d4690da-28b6-48c5-91d0-fd642bde3a7b)

![Screenshot_20240827_164359](https://github.com/user-attachments/assets/902c95ea-caf6-442f-a487-d5aea5497eaf)

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior using example_31 in examples.py and inspect how CraftError renders its message and resolution at the default brief verbosity. Done means a message containing a newline no longer produces inconsistent or extraneous whitespace before the resolution section.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.