SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Crashing with terminal modes that don't support color

LeonBlade opened this issue ยท 4 comments

commented

Recently a user that joined the Discord had a problem where they were getting a Null exception while trying to install or run the StardewModdingAPI executable. The line in question is Console.ForegroundColor and it results in the variable format being null and triggering a null exception.

The stack trace points back to here:

Console.ForegroundColor = color;

Or any of the four uses in the installer like here:

Console.ForegroundColor = ConsoleColor.DarkGray;

For macOS (like this user was using) the answer is to set the "Declare terminal as" in "Advanced" tab of the selected Profile to be "xterm-256color" or anything with color.
macOS Terminal Settings

It's obviously desirable to have color in the terminal, but for cases like this most users won't have any idea what broke and how to fix it. There are a few obvious solutions like adding a troubleshooting section in the install guide, or abstracting the Console.ForegroundColor used in various places with something that can catch this and default to a colorless mode.

Personally, I would opt for doing this in the code as it makes things easier for troubleshooting the end user, perhaps even outputting something in the terminal about not supporting color and even linking to a page where you can learn how to fix it.

Regardless, I figured that I'd create an issue for this as I can see this being a problem for people again in the future.

commented

Hi @LeonBlade. Do you have an example of the displayed error?

commented

Hey there @Pathoschild. This is the error they sent me.
https://www.dropbox.com/s/sya5l90i4mx9g5m/Screenshot%202016-12-28%2002.16.40.tiff?dl=0

The error comes back from the color like I said earlier.

commented

Tentatively fixed in develop for the upcoming 1.6 release, but I can't test it myself since I don't have Mac. I'll keep this open until the beta is available and someone can confirm.

commented

Fix confirmed with @LeonBlade. Thanks!