briefcase icon indicating copy to clipboard operation
briefcase copied to clipboard

Add helper for formatting long warning messages

Open mhsmith opened this issue 1 month ago • 1 comments

What is the problem or limitation you are having?

The code contains a lot of messages like this:

https://github.com/beeware/briefcase/blob/9bbd110f1321be189b7a6c55102942b3e5509ea9/src/briefcase/integrations/java.py#L117-L136

This has several problems:

  • It completely messes up the indentation of the surrounding code.

  • When the message contains placeholders, it's difficult to get the wrapping and alignment correct for all possible values. For example, the asterisk box alignment here is incorrect when the Java version contains 2 characters:

    *************************************************************************
    ** WARNING: JAVA_HOME does not point to a Java 17 JDK            **
    *************************************************************************
    

Describe the solution you'd like

Add a helper function that takes a message, and optionally a title, and formats it automatically with textwrap or something similar. The places that call the function can then use normal indentation with no soft line breaks, like this:

https://github.com/beeware/briefcase/blob/9bbd110f1321be189b7a6c55102942b3e5509ea9/src/briefcase/exceptions.py#L135-L142

At first, there's no need to use this function in every possible place. It's enough to prove that it works by using it in a few places whose messages are covered by the unit tests.

Describe alternatives you've considered

Maybe Rich has something like this already?

Additional context

  • https://github.com/beeware/briefcase/pull/2533#discussion_r2512421086

mhsmith avatar Nov 11 '25 09:11 mhsmith

Hello, I started solving this issue. Give me couple of days.

otekraden avatar Nov 11 '25 20:11 otekraden