changeset 1592:9303bacae890

remember init.luan exception
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 18 Mar 2021 23:52:49 -0600
parents 85cd316f0cdb
children ea62c2316b2e
files src/luan/modules/http/LuanHandler.java
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Thu Mar 18 23:36:15 2021 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Thu Mar 18 23:52:49 2021 -0600
@@ -43,6 +43,7 @@
 	private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
 	private volatile Luan currentLuan;
 	private volatile boolean isDisabled = false;
+	private volatile LuanException initErr;
 
 	private static final Method resetLuanMethod;
 	private static final Method evalInRootMethod;
@@ -75,7 +76,7 @@
 		}
 		if( domain != null )
 			logger.info("new "+domain);
-		currentLuan = newLuan();
+		newLuan();
 	}
 
 	protected void finalize() throws Throwable {
@@ -83,22 +84,24 @@
 			logger.info("gc "+domain);
 	}
 
-	private Luan newLuan() {
+	private void newLuan() {
 		Luan luan;
 		synchronized(luanInit) {
 			luan = new Luan(luanInit);
 		}
+		initErr = null;
 		LuanLogger.startThreadLogging(luan);
 		try {
 			PackageLuan.load(luan,"site:/init.luan",null);
 		} catch(LuanException e) {
 			//e.printStackTrace();
+			initErr = e;
 			String err = e.getLuanStackTraceString();
 			logger.error(err);
 		} finally {
 			LuanLogger.endThreadLogging();
 		}
-		return luan;
+		currentLuan = luan;
 	}
 
 	static final String NOT_FOUND = "luan-not-found";
@@ -118,6 +121,8 @@
 		rwLock.readLock().lock();
 		LuanLogger.startThreadLogging(currentLuan);
 		try {
+			if( initErr != null )
+				throw initErr;
 			return service(request,notFound);
 		} catch(LuanException e) {
 			String err = e.getLuanStackTraceString();
@@ -170,7 +175,7 @@
 			rwLock.writeLock().lock();
 			try {
 				close();
-				currentLuan = newLuan();
+				newLuan();
 			} finally {
 				rwLock.writeLock().unlock();
 			}