core: Use a separate function to format failure message for str::slice() errors

Using strcat's idea, this makes sure no formatting code from failure is
inlined when str::slice() is inlined.