formatFailureText function
Renders a readable message plus stack when available.
Accepts String, Failure, Error / Exception and any other thrown
object; pass stack when the caller caught one separately. ANSI is
stripped and the first line is never duplicated.
Implementation
String formatFailureText(Object? error, [StackTrace? stack]) {
if (error == null) return stripAnsi((stack?.toString() ?? '')).trim();
if (error is Failure) {
return stripAnsi(
joinMessageStack(error.message, error.stack ?? stack?.toString()),
).trim();
}
if (error is String) {
return stripAnsi(joinMessageStack(error, stack?.toString())).trim();
}
return stripAnsi(
joinMessageStack(error.toString(), stack?.toString()),
).trim();
}