1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-12 02:10:30 +00:00

Print stack traces/add logging messages in several places

This will hopefully make it easier to track down various issues which
might otherwise go unnoticed or provide little information.

The main areas modified are those that external APIs may provide values
for or interact with: various providers and ILuaObject/IPeripheral
implementations. However, we do also log in a couple of other places
which indicate a problem with this, or another, mod.
This commit is contained in:
SquidDev 2017-05-08 19:55:51 +01:00
parent bdc438fc62
commit 44ba4069c1
8 changed files with 33 additions and 17 deletions

View File

@ -609,7 +609,7 @@ public class ComputerCraft
}
catch( Exception e )
{
// mod misbehaved, ignore it
Logger.error( "Peripheral provider " + peripheralProvider + " errored.", e );
}
}
return null;
@ -653,7 +653,7 @@ public class ComputerCraft
}
catch( Exception e )
{
// mod misbehaved, ignore it
Logger.error( "Bundled redstone provider " + bundledRedstoneProvider + " errored.", e );
}
}
return combinedSignal;
@ -677,6 +677,7 @@ public class ComputerCraft
catch( Exception e )
{
// mod misbehaved, ignore it
Logger.error( "Media provider " + mediaProvider + " errored.", e );
}
}
return null;

View File

@ -14,6 +14,7 @@ import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.core.apis.*;
import dan200.computercraft.core.filesystem.FileSystem;
import dan200.computercraft.core.filesystem.FileSystemException;
import dan200.computercraft.core.logger.Logger;
import dan200.computercraft.core.lua.ILuaMachine;
import dan200.computercraft.core.lua.LuaJLuaMachine;
import dan200.computercraft.core.terminal.Terminal;
@ -469,7 +470,7 @@ public class Computer
}
catch( FileSystemException e )
{
e.printStackTrace();
Logger.error( "Cannot mount rom", e );
return false;
}
}

View File

@ -6,6 +6,8 @@
package dan200.computercraft.core.computer;
import dan200.computercraft.core.logger.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.WeakHashMap;
@ -106,8 +108,7 @@ public class ComputerThread
try {
task.execute();
} catch( Throwable e ) {
System.out.println( "ComputerCraft: Error running task." );
e.printStackTrace();
Logger.error( "Error running task", e );
}
}
} );
@ -139,7 +140,7 @@ public class ComputerThread
// Step 3: abandon
if( worker.isAlive() )
{
//System.out.println( "computercraft: Warning! Failed to abort Computer " + computercraft.getDescription() + ". Dangling lua thread could cause errors." );
Logger.warn( "Failed to abort Computer " + computer.getID() + ". Dangling lua thread could cause errors." );
worker.interrupt();
}
}

View File

@ -15,6 +15,7 @@ import dan200.computercraft.core.apis.ILuaAPI;
import dan200.computercraft.core.computer.Computer;
import dan200.computercraft.core.computer.ITask;
import dan200.computercraft.core.computer.MainThread;
import dan200.computercraft.core.logger.Logger;
import org.luaj.vm2.*;
import org.luaj.vm2.lib.OneArgFunction;
import org.luaj.vm2.lib.VarArgFunction;
@ -183,6 +184,7 @@ public class LuaJLuaMachine implements ILuaMachine
}
catch( LuaError e )
{
Logger.warn( "Could not load bios.lua ", e );
if( m_mainRoutine != null )
{
((LuaThread)m_mainRoutine).abandon();
@ -327,7 +329,8 @@ public class LuaJLuaMachine implements ILuaMachine
{
final int method = i;
final ILuaObject apiObject = object;
table.set( methods[i], new VarArgFunction() {
final String methodName = methods[i];
table.set( methodName, new VarArgFunction() {
@Override
public Varargs invoke( Varargs _args )
{
@ -412,6 +415,7 @@ public class LuaJLuaMachine implements ILuaMachine
}
catch( Throwable t )
{
Logger.error( "Error running task", t);
m_computer.queueEvent( "task_complete", new Object[] {
taskID, false, "Java Exception Thrown: " + t.toString()
} );
@ -478,6 +482,7 @@ public class LuaJLuaMachine implements ILuaMachine
}
catch( Throwable t )
{
Logger.error( "Error calling " + methodName + " on " + apiObject, t );
throw new LuaError( "Java Exception Thrown: " + t.toString(), 0 );
}
return LuaValue.varargsOf( toValues( results, 0 ) );

View File

@ -11,6 +11,7 @@ import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.ILuaTask;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.core.apis.ILuaAPI;
import dan200.computercraft.core.logger.Logger;
import dan200.computercraft.shared.computer.blocks.TileCommandComputer;
import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block;
@ -98,6 +99,7 @@ public class CommandAPI implements ILuaAPI
}
catch( Throwable t )
{
Logger.error( "Error running command.", t );
return new Object[]{ false, createOutput( "Java Exception Thrown: " + t.toString() ) };
}
}
@ -208,6 +210,7 @@ public class CommandAPI implements ILuaAPI
catch( Throwable t )
{
// Ignore buggy command
Logger.error( "Error running command.", t );
}
}
}

View File

@ -7,6 +7,7 @@
package dan200.computercraft.shared.network;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.core.logger.Logger;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.FMLNetworkEvent;
@ -24,7 +25,7 @@ public class PacketHandler
}
catch( Exception e )
{
e.printStackTrace();
Logger.error( "Error handling packet", e );
}
}
@ -39,7 +40,7 @@ public class PacketHandler
}
catch( Exception e )
{
e.printStackTrace();
Logger.error( "Error handling packet", e );
}
}
}

View File

@ -8,6 +8,7 @@ package dan200.computercraft.shared.proxy;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.core.logger.Logger;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.items.ComputerItemFactory;
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
@ -83,7 +84,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
int id = upgrade.getLegacyUpgradeID();
if( id >= 0 && id < 64 )
{
throw new RuntimeException( "Error registering '"+upgrade.getUnlocalisedAdjective()+" Turtle'. Legacy UpgradeID '"+id+"' is reserved by ComputerCraft" );
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. Legacy UpgradeID '" + id + "' is reserved by ComputerCraft" );
}
// Register
@ -117,6 +118,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
}
catch( Exception e )
{
Logger.error("Error checking stackability of items", e);
}
}
return null;
@ -253,13 +255,13 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
{
if( legacyID >= Short.MAX_VALUE )
{
throw new RuntimeException( "Error registering '"+upgrade.getUnlocalisedAdjective()+" Turtle'. UpgradeID '"+legacyID+"' is out of range" );
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is out of range" );
}
ITurtleUpgrade existing = m_legacyTurtleUpgrades.get( legacyID );
if( existing != null )
{
throw new RuntimeException( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + legacyID + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
}
}
@ -267,7 +269,7 @@ public abstract class CCTurtleProxyCommon implements ICCTurtleProxy
ITurtleUpgrade existing = m_turtleUpgrades.get( id );
if( existing != null )
{
throw new RuntimeException( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
throw Logger.loggedError( "Error registering '" + upgrade.getUnlocalisedAdjective() + " Turtle'. UpgradeID '" + id + "' is already registered by '" + existing.getUnlocalisedAdjective() + " Turtle'" );
}
// Register

View File

@ -1,5 +1,7 @@
package dan200.computercraft.shared.util;
import dan200.computercraft.core.logger.Logger;
import java.io.*;
public class IDAssigner
@ -50,6 +52,7 @@ public class IDAssigner
}
catch( NumberFormatException e )
{
Logger.error( "Unexpected file '" + content + "' in '" + location.getAbsolutePath() + "'", e );
}
}
}
@ -82,7 +85,7 @@ public class IDAssigner
}
catch( IOException e )
{
e.printStackTrace();
Logger.error( "Cannot open ID file '" + lastidFile + "'", e );
return 0;
}
@ -92,7 +95,7 @@ public class IDAssigner
}
catch( NumberFormatException e )
{
e.printStackTrace();
Logger.error( "Cannot parse ID file '" + lastidFile + "', perhaps it is corrupt?", e );
return 0;
}
}
@ -107,8 +110,7 @@ public class IDAssigner
}
catch( IOException e )
{
System.out.println( "An error occured while trying to create the computer folder. Please check you have relevant permissions." );
e.printStackTrace();
Logger.error( "An error occured while trying to create the computer folder. Please check you have relevant permissions.", e );
}
return id;