Skip to content

Add helper for formatting long warning messages #2559

@mhsmith

Description

@mhsmith

What is the problem or limitation you are having?

The code contains a lot of messages like this:

else:
install_message = f"""
*************************************************************************
** WARNING: JAVA_HOME does not point to a Java {cls.JDK_MAJOR_VER} JDK **
*************************************************************************
Android requires a Java {cls.JDK_MAJOR_VER} JDK, but the location pointed to by the
JAVA_HOME environment variable:
{java_home}
isn't a Java {cls.JDK_MAJOR_VER} JDK (it appears to be Java {version_str}).
Briefcase will proceed using its own JDK instance.
*************************************************************************
"""
except OSError:
install_message = f"""

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:

super().__init__(
msg=(
f"Briefcase cannot install {tool} on this machine."
f"\n\n"
f"Install {tool} manually and specify the installation "
f"directory in the {env_var} environment variable."
)
)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew features, or improvements to existing features.good first issueIs this your first time contributing? This could be a good place to start!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions