From fc19579d7c58972108ba8d9615896b002a22def6 Mon Sep 17 00:00:00 2001 From: James Harkins Date: Mon, 27 Feb 2012 22:09:00 +0800 Subject: [PATCH] Protected backtrace: don't print all of a very long sourceCode string --- SCClassLibrary/Common/Core/Error.sc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SCClassLibrary/Common/Core/Error.sc b/SCClassLibrary/Common/Core/Error.sc index e6e4318d4..6d8337ae1 100644 --- a/SCClassLibrary/Common/Core/Error.sc +++ b/SCClassLibrary/Common/Core/Error.sc @@ -30,7 +30,7 @@ Exception { ^this.errorString.tr($ , $_).tr($\n, $_); } postProtectedBacktrace { - var out, currentFrame, def, ownerClass, methodName, pos; + var out, currentFrame, def, ownerClass, methodName, pos, tempStr; out = CollStream.new; "\nPROTECTED CALL STACK:".postln; currentFrame = protectedBacktrace; @@ -45,7 +45,14 @@ Exception { out << "\t%:%\t%\n".format(ownerClass, methodName, currentFrame.address); }, { out << "\ta FunctionDef\t%\n".format(currentFrame.address); - out << "\t\tsourceCode = %\n".format(def.sourceCode ? ""); + // sourceCode may be ridiculously huge, + // so steal the technique from Object:asString to reduce the printed size + tempStr = String.streamContentsLimit({ |stream| + stream << "\t\tsourceCode = " <<< (def.sourceCode ? ""); + }, 512); + out << tempStr; + if(tempStr.size >= 512) { out << "...etc..." << $" }; + out << Char.nl; }); def.argNames.do({|name, i| out << "\t\targ % = %\n".format(name, currentFrame.args[i]); -- 2.11.4.GIT