Skip to content

Commit fa1f075

Browse files
committed
LDEV-6112 - do not suppress exceptions
1 parent d95ead0 commit fa1f075

30 files changed

+363
-340
lines changed

core/src/main/java/lucee/commons/io/log/LogFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lucee.runtime.config.Prop;
1212
import lucee.runtime.config.PropFactory;
1313
import lucee.runtime.db.ClassDefinition;
14+
import lucee.runtime.exp.PageException;
1415
import lucee.runtime.op.Caster;
1516
import lucee.runtime.type.Array;
1617
import lucee.runtime.type.ArrayImpl;
@@ -34,13 +35,12 @@ public static LogFactory getInstance() {
3435
}
3536

3637
@Override
37-
public LoggerAndSourceData evaluate(Config config, String name, Object val, LoggerAndSourceData defaultValue) {
38+
public LoggerAndSourceData evaluate(Config config, String name, Object val) throws PageException {
3839
try {
3940
return loadLogger((ConfigPro) config, name, Caster.toStruct(val));
4041
}
4142
catch (Exception e) {
42-
LogUtil.log("log-factory", e);
43-
return defaultValue;
43+
throw Caster.toPageException(e);
4444
}
4545
}
4646

core/src/main/java/lucee/commons/io/res/ResourceProviderDefFactory.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import lucee.runtime.config.PropFactory;
1010
import lucee.runtime.db.ClassDefinition;
1111
import lucee.runtime.exp.ApplicationException;
12+
import lucee.runtime.exp.PageException;
1213
import lucee.runtime.op.Caster;
1314
import lucee.runtime.type.Array;
1415
import lucee.runtime.type.ArrayImpl;
@@ -43,29 +44,39 @@ public static ResourceProviderDefFactory getInstance(boolean schemeRequired) {
4344
}
4445

4546
@Override
46-
public ResourceProviderDef evaluate(Config config, String name, Object val, ResourceProviderDef defaultValue) {
47+
public ResourceProviderDef evaluate(Config config, String name, Object val) throws PageException {
4748
try {
49+
// can be an array with a single entry
50+
Array arr = Caster.toArray(val, null);
51+
if (arr != null) {
52+
if (arr.size() != 1) throw new ApplicationException("only an array with a single item is allowed");
53+
val = arr.getE(1);
54+
}
4855

49-
Struct defaultProvider = Caster.toStruct(val, null);
50-
if (defaultProvider == null) return defaultValue;
56+
Struct defaultProvider = Caster.toStruct(val);
5157

5258
ClassDefinition cd = ConfigFactoryImpl.getClassDefinition(config, defaultProvider, "", config.getIdentification());
5359

5460
String scheme = ConfigFactoryImpl.getAttr(config, defaultProvider, "scheme");
5561
if (schemeRequired && StringUtil.isEmpty(scheme)) {
5662
throw new ApplicationException("scheme is required");
5763
}
58-
if (!cd.hasClass() || "lucee.commons.io.res.type.ftp.FTPResourceProvider".equals(cd.getClassName())) return defaultValue;
64+
if (!cd.hasClass()) {
65+
throw new ApplicationException("no class defined");
66+
67+
}
68+
if ("lucee.commons.io.res.type.ftp.FTPResourceProvider".equals(cd.getClassName())) {
69+
throw new ApplicationException("[" + cd.getClassName() + "] no longer supported");
70+
}
5971

6072
Map<String, String> args = ConfigFactoryImpl.toArguments(defaultProvider, "arguments", true, false);
6173

6274
return new ResourceProviderDef(scheme, cd, args);
6375

6476
}
6577
catch (Exception ex) {
66-
ConfigFactoryImpl.log(config, ex);
78+
throw Caster.toPageException(ex);
6779
}
68-
return defaultValue;
6980
}
7081

7182
@Override

core/src/main/java/lucee/runtime/MappingFactory.java

Lines changed: 78 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package lucee.runtime;
22

33
import lucee.commons.io.SystemUtil;
4-
import lucee.commons.io.log.LogUtil;
54
import lucee.commons.lang.StringUtil;
65
import lucee.runtime.config.Config;
76
import lucee.runtime.config.ConfigFactoryImpl;
87
import lucee.runtime.config.ConfigPro;
98
import lucee.runtime.config.ConfigUtil;
109
import lucee.runtime.config.Prop;
1110
import lucee.runtime.config.PropFactory;
11+
import lucee.runtime.exp.ApplicationException;
12+
import lucee.runtime.exp.PageException;
1213
import lucee.runtime.listener.ApplicationListener;
1314
import lucee.runtime.listener.ModernAppListener;
1415
import lucee.runtime.op.Caster;
@@ -43,105 +44,97 @@ public static MappingFactory getInstance(short type) {
4344
}
4445

4546
@Override
46-
public Mapping evaluate(Config config, String name, Object val, Mapping defaultValue) {
47-
try {
48-
Struct el = Caster.toStruct(val);
49-
if (el == null) return null;
50-
51-
String virtual = null;
52-
if (TYPE_REGULAR != type) {
53-
virtual = ConfigFactoryImpl.getAttr(config, el, "virtual");
54-
}
55-
if (StringUtil.isEmpty(virtual)) virtual = name;
56-
57-
String physical = ConfigFactoryImpl.getAttr(config, el, "physical");
58-
String archive = ConfigFactoryImpl.getAttr(config, el, "archive");
59-
String strListType = ConfigFactoryImpl.getAttr(config, el, "listenerType");
60-
if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listener-type");
61-
if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listenertype");
62-
63-
String strListMode = ConfigFactoryImpl.getAttr(config, el, "listenerMode");
64-
if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listener-mode");
65-
if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listenermode");
47+
public Mapping evaluate(Config config, String name, Object val) throws PageException {
6648

67-
boolean readonly = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "readonly"), false);
68-
boolean hidden = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "hidden"), false);
69-
boolean toplevel = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "toplevel"), true);
49+
Struct el = Caster.toStruct(val);
7050

71-
boolean appMapping = false;
72-
boolean ignoreVirtual = false;
73-
74-
// regular type check
75-
if (TYPE_REGULAR == type) {
76-
// lucee
77-
if ("/lucee/".equalsIgnoreCase(virtual)) {
78-
if (StringUtil.isEmpty(strListType, true)) strListType = "modern";
79-
if (StringUtil.isEmpty(strListMode, true)) strListMode = "curr2root";
80-
toplevel = true;
81-
}
82-
}
83-
else if (TYPE_COMPONENT == type) {
84-
if ("{lucee-web}/components/".equals(physical) || "{lucee-server}/components/".equals(physical)) return null;
85-
toplevel = true;
86-
ignoreVirtual = true;
87-
}
88-
else if (TYPE_CUSTOM_TAG == type) {
89-
if ("{lucee-web}/customtags/".equals(physical) || "{lucee-server}/customtags/".equals(physical)) return null;
51+
String virtual = null;
52+
if (TYPE_REGULAR != type) {
53+
virtual = ConfigFactoryImpl.getAttr(config, el, "virtual");
54+
}
55+
if (StringUtil.isEmpty(virtual)) virtual = name;
56+
57+
String physical = ConfigFactoryImpl.getAttr(config, el, "physical");
58+
String archive = ConfigFactoryImpl.getAttr(config, el, "archive");
59+
String strListType = ConfigFactoryImpl.getAttr(config, el, "listenerType");
60+
if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listener-type");
61+
if (StringUtil.isEmpty(strListType)) strListType = ConfigFactoryImpl.getAttr(config, el, "listenertype");
62+
63+
String strListMode = ConfigFactoryImpl.getAttr(config, el, "listenerMode");
64+
if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listener-mode");
65+
if (StringUtil.isEmpty(strListMode)) strListMode = ConfigFactoryImpl.getAttr(config, el, "listenermode");
66+
67+
boolean readonly = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "readonly"), false);
68+
boolean hidden = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "hidden"), false);
69+
boolean toplevel = ConfigFactoryImpl.toBoolean(ConfigFactoryImpl.getAttr(config, el, "toplevel"), true);
70+
71+
boolean appMapping = false;
72+
boolean ignoreVirtual = false;
73+
74+
// regular type check
75+
if (TYPE_REGULAR == type) {
76+
// lucee
77+
if ("/lucee/".equalsIgnoreCase(virtual)) {
78+
if (StringUtil.isEmpty(strListType, true)) strListType = "modern";
79+
if (StringUtil.isEmpty(strListMode, true)) strListMode = "curr2root";
9080
toplevel = true;
91-
ignoreVirtual = true;
9281
}
82+
}
83+
else if (TYPE_COMPONENT == type) {
84+
if ("{lucee-web}/components/".equals(physical) || "{lucee-server}/components/".equals(physical)) return null;
85+
toplevel = true;
86+
ignoreVirtual = true;
87+
}
88+
else if (TYPE_CUSTOM_TAG == type) {
89+
if ("{lucee-web}/customtags/".equals(physical) || "{lucee-server}/customtags/".equals(physical)) return null;
90+
toplevel = true;
91+
ignoreVirtual = true;
92+
}
9393

94-
int listenerMode = ConfigUtil.toListenerMode(strListMode, -1);
95-
int listenerType = ConfigUtil.toListenerType(strListType, -1);
94+
int listenerMode = ConfigUtil.toListenerMode(strListMode, -1);
95+
int listenerType = ConfigUtil.toListenerType(strListType, -1);
9696

97-
ApplicationListener listener = null;
98-
if (TYPE_REGULAR == type) {
99-
listener = ConfigUtil.loadListener(listenerType, null);
100-
if (listener != null || listenerMode != -1) {
101-
// type
102-
if (listener == null) listener = ConfigUtil.loadListener(ConfigUtil.toListenerType(config.getApplicationListener().getType(), -1), null);
103-
if (listener == null) listener = new ModernAppListener();
104-
105-
// mode
106-
if (listenerMode == -1) {
107-
listenerMode = config.getApplicationListener().getMode();
108-
}
109-
listener.setMode(listenerMode);
97+
ApplicationListener listener = null;
98+
if (TYPE_REGULAR == type) {
99+
listener = ConfigUtil.loadListener(listenerType, null);
100+
if (listener != null || listenerMode != -1) {
101+
// type
102+
if (listener == null) listener = ConfigUtil.loadListener(ConfigUtil.toListenerType(config.getApplicationListener().getType(), -1), null);
103+
if (listener == null) listener = new ModernAppListener();
110104

105+
// mode
106+
if (listenerMode == -1) {
107+
listenerMode = config.getApplicationListener().getMode();
111108
}
112-
}
113-
else if (TYPE_CUSTOM_TAG == type) {
114-
listenerMode = -1;
115-
listenerType = -1;
116-
// TODO i guess this applies for component as well?
117-
}
109+
listener.setMode(listenerMode);
118110

119-
// physical!=null &&
120-
if ((physical != null || archive != null)) {
111+
}
112+
}
113+
else if (TYPE_CUSTOM_TAG == type) {
114+
listenerMode = -1;
115+
listenerType = -1;
116+
// TODO i guess this applies for component as well?
117+
}
121118

122-
short insTemp = inspectTemplate(config, el);
119+
// physical!=null &&
120+
if ((physical != null || archive != null)) {
123121

124-
int insTempSlow = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalSlow"), ConfigPro.INSPECT_INTERVAL_UNDEFINED);
125-
int insTempFast = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalFast"), ConfigPro.INSPECT_INTERVAL_UNDEFINED);
126-
if (TYPE_REGULAR == type) {
127-
if ("/lucee/".equalsIgnoreCase(virtual) || "/lucee".equalsIgnoreCase(virtual) || "/lucee-server/".equalsIgnoreCase(virtual)
128-
|| "/lucee-server-context".equalsIgnoreCase(virtual))
129-
insTemp = ConfigPro.INSPECT_AUTO;
130-
}
131-
String primary = ConfigFactoryImpl.getAttr(config, el, "primary");
132-
boolean physicalFirst = primary == null || !"archive".equalsIgnoreCase(primary);
122+
short insTemp = inspectTemplate(config, el);
133123

134-
return new MappingImpl(config, virtual, physical, archive, insTemp, insTempSlow, insTempFast, physicalFirst, hidden, readonly, toplevel, appMapping, ignoreVirtual,
135-
listener, listenerMode, listenerType);
124+
int insTempSlow = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalSlow"), ConfigPro.INSPECT_INTERVAL_UNDEFINED);
125+
int insTempFast = Caster.toIntValue(ConfigFactoryImpl.getAttr(config, el, "inspectTemplateIntervalFast"), ConfigPro.INSPECT_INTERVAL_UNDEFINED);
126+
if (TYPE_REGULAR == type) {
127+
if ("/lucee/".equalsIgnoreCase(virtual) || "/lucee".equalsIgnoreCase(virtual) || "/lucee-server/".equalsIgnoreCase(virtual)
128+
|| "/lucee-server-context".equalsIgnoreCase(virtual))
129+
insTemp = ConfigPro.INSPECT_AUTO;
136130
}
131+
String primary = ConfigFactoryImpl.getAttr(config, el, "primary");
132+
boolean physicalFirst = primary == null || !"archive".equalsIgnoreCase(primary);
137133

134+
return new MappingImpl(config, virtual, physical, archive, insTemp, insTempSlow, insTempFast, physicalFirst, hidden, readonly, toplevel, appMapping, ignoreVirtual,
135+
listener, listenerMode, listenerType);
138136
}
139-
catch (Exception ex) {
140-
LogUtil.log("mapping-factory", ex);
141-
return defaultValue;
142-
}
143-
144-
return null;
137+
throw new ApplicationException("you need to define [physical] or [archive]");
145138
}
146139

147140
private static short inspectTemplate(Config config, Struct data) {

core/src/main/java/lucee/runtime/ai/AIEngineFactory.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,12 @@ public static AIEngine getExistingInstance(String id, AIEngine defaultValue) {
105105
}
106106

107107
@Override
108-
public AIEngine evaluate(Config config, String name, Object val, AIEngine defaultValue) {
109-
Struct data = Caster.toStruct(val, null);
110-
if (data == null) return defaultValue;
108+
public AIEngine evaluate(Config config, String name, Object val) throws PageException {
111109
try {
112-
return getInstance(config, name, data);
110+
return getInstance(config, name, Caster.toStruct(val));
113111
}
114112
catch (Exception e) {
115-
ConfigFactoryImpl.log(config, e);
116-
return defaultValue;
113+
throw Caster.toPageException(e);
117114
}
118115
}
119116

core/src/main/java/lucee/runtime/cache/CacheConnectionFactory.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lucee.runtime.config.Prop;
99
import lucee.runtime.config.PropFactory;
1010
import lucee.runtime.db.ClassDefinition;
11+
import lucee.runtime.exp.PageException;
1112
import lucee.runtime.op.Caster;
1213
import lucee.runtime.type.Struct;
1314
import lucee.runtime.type.StructImpl;
@@ -25,10 +26,9 @@ public static CacheConnectionFactory getInstance() {
2526
}
2627

2728
@Override
28-
public CacheConnection evaluate(Config c, String name, Object val, CacheConnection defaultValue) {
29+
public CacheConnection evaluate(Config c, String name, Object val) throws PageException {
2930
ConfigPro config = (ConfigPro) c;
30-
Struct data = Caster.toStruct(val, null);
31-
if (data == null) return defaultValue;
31+
Struct data = Caster.toStruct(val);
3232
ClassDefinition cd;
3333
CacheConnection cc;
3434

@@ -59,9 +59,8 @@ else if (cd.getClassName() != null && (cd.getClassName().endsWith(".extension.io
5959
catch (Throwable t) {
6060
ExceptionUtil.rethrowIfNecessary(t);
6161
ConfigFactoryImpl.log(config, t);
62+
throw Caster.toPageException(t);
6263
}
63-
64-
return defaultValue;
6564
}
6665

6766
@Override

core/src/main/java/lucee/runtime/cfx/customtag/JavaCFXTagClassFactory.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package lucee.runtime.cfx.customtag;
22

3-
import lucee.commons.lang.ExceptionUtil;
43
import lucee.commons.lang.StringUtil;
54
import lucee.runtime.config.Config;
65
import lucee.runtime.config.ConfigFactoryImpl;
76
import lucee.runtime.config.Prop;
87
import lucee.runtime.config.PropFactory;
98
import lucee.runtime.db.ClassDefinition;
9+
import lucee.runtime.exp.ApplicationException;
10+
import lucee.runtime.exp.PageException;
1011
import lucee.runtime.op.Caster;
1112
import lucee.runtime.type.Array;
1213
import lucee.runtime.type.ArrayImpl;
@@ -27,9 +28,8 @@ public static JavaCFXTagClassFactory getInstance() {
2728
}
2829

2930
@Override
30-
public CFXTagClass evaluate(Config config, String name, Object val, CFXTagClass defaultValue) {
31-
Struct cfxTag = Caster.toStruct(val, null);
32-
if (cfxTag == null) return defaultValue;
31+
public CFXTagClass evaluate(Config config, String name, Object val) throws PageException {
32+
Struct cfxTag = Caster.toStruct(val);
3333

3434
try {
3535

@@ -42,14 +42,13 @@ public CFXTagClass evaluate(Config config, String name, Object val, CFXTagClass
4242
if (!StringUtil.isEmpty(name) && cd.hasClass()) {
4343
return new JavaCFXTagClass(name, cd);
4444
}
45+
throw new ApplicationException("name is required");
4546
}
46-
47+
throw new ApplicationException("type [" + type + "] is not supported, only type [java] is supported");
4748
}
48-
catch (Throwable t) {
49-
ExceptionUtil.rethrowIfNecessary(t);
50-
ConfigFactoryImpl.log(config, t);
49+
catch (Exception ex) {
50+
throw Caster.toPageException(ex);
5151
}
52-
return defaultValue;
5352
}
5453

5554
@Override

0 commit comments

Comments
 (0)