From 28ced402d812e86f55e48af55fd9e8a5150a116a Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 25 Oct 2012 02:52:20 +0100 Subject: [PATCH] When scripts generate expected exceptions (e.g. due to checked bad parameter) throw ScriptException instead of just a plain old exception. This is to make it easier to distinguish these exceptions from unexpected OpenSimulator problems internally and in regression tests. No functional changes. --- .../Framework/Scenes/Scene.PacketHandlers.cs | 5 ++- .../Shared/Api/Implementation/LSL_Api.cs | 4 +- .../Shared/Api/Implementation/MOD_Api.cs | 10 ++--- .../Shared/Api/Implementation/OSSL_Api.cs | 2 +- .../ScriptEngine/Shared/ScriptException.cs | 40 +++++++++++++++++++ 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 OpenSim/Region/ScriptEngine/Shared/ScriptException.cs diff --git a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs index 6e53951003..99bf72a1d2 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.PacketHandlers.cs @@ -38,7 +38,6 @@ namespace OpenSim.Region.Framework.Scenes { public partial class Scene { - protected void SimChat(byte[] message, ChatTypeEnum type, int channel, Vector3 fromPos, string fromName, UUID fromID, UUID targetID, bool fromAgent, bool broadcast) { @@ -66,6 +65,10 @@ namespace OpenSim.Region.Framework.Scenes args.From = fromName; args.TargetUUID = targetID; +// m_log.DebugFormat( +// "[SCENE]: Sending message {0} on channel {1}, type {2} from {3}, broadcast {4}", +// args.Message.Replace("\n", "\\n"), args.Channel, args.Type, fromName, broadcast); + if (broadcast) EventManager.TriggerOnChatBroadcast(this, args); else diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index b2c65794ae..0a0e68fca7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -10589,12 +10589,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api internal void Deprecated(string command) { - throw new Exception("Command deprecated: " + command); + throw new ScriptException("Command deprecated: " + command); } internal void LSLError(string msg) { - throw new Exception("LSL Runtime Error: " + msg); + throw new ScriptException("LSL Runtime Error: " + msg); } public delegate void AssetRequestCallback(UUID assetID, AssetBase asset); diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs index 7844c75155..6ed9ffdc17 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs @@ -95,13 +95,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api internal void MODError(string msg) { - throw new Exception("MOD Runtime Error: " + msg); + throw new ScriptException("MOD Runtime Error: " + msg); } - // - //Dumps an error message on the debug console. - // - + /// + /// Dumps an error message on the debug console. + /// + /// internal void MODShoutError(string message) { if (message.Length > 1023) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 275d436f83..09722e7c28 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -206,7 +206,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api internal void OSSLError(string msg) { - throw new Exception("OSSL Runtime Error: " + msg); + throw new ScriptException("OSSL Runtime Error: " + msg); } /// diff --git a/OpenSim/Region/ScriptEngine/Shared/ScriptException.cs b/OpenSim/Region/ScriptEngine/Shared/ScriptException.cs new file mode 100644 index 0000000000..ae67fc5585 --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/ScriptException.cs @@ -0,0 +1,40 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; + +namespace OpenSim.Region.ScriptEngine.Shared +{ + public class ScriptException : Exception + { + public ScriptException() : base() {} + + public ScriptException(string message) : base(message) {} + + public ScriptException(string message, Exception innerException) : base(message, innerException) {} + } +} \ No newline at end of file