Skip to content

Commit

Permalink
LDEV-5010 - improve exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 14, 2024
1 parent c599a33 commit 71ba37f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions core/src/main/java/lucee/runtime/functions/file/FileWrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package lucee.runtime.functions.file;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import lucee.commons.io.IOUtil;
import lucee.commons.io.res.Resource;
Expand All @@ -28,6 +29,7 @@
import lucee.runtime.PageContextImpl;
import lucee.runtime.PageSourcePool;
import lucee.runtime.exp.ApplicationException;
import lucee.runtime.exp.ExpressionException;
import lucee.runtime.exp.PageException;
import lucee.runtime.op.Caster;

Expand Down Expand Up @@ -63,9 +65,7 @@ public static String call(PageContext pc, Object obj, Object data, String charse
fsw.write(data);
}
catch (IOException e) {
ApplicationException ae = new ApplicationException("Invalid file [" + Caster.toResource(pc, obj, false) + "]");
ExceptionUtil.initCauseEL(ae, e);
throw ae;
throw toApplicationException(pc, obj, charset, e);
}
finally {
if (close) IOUtil.closeEL(fsw);
Expand All @@ -74,4 +74,20 @@ public static String call(PageContext pc, Object obj, Object data, String charse

return null;
}

private static ApplicationException toApplicationException(PageContext pc, Object obj, String charset, IOException e) throws ExpressionException {
ApplicationException ae;
if (e instanceof UnsupportedEncodingException) {
ae = new ApplicationException("Failed to write to file [" + Caster.toResource(pc, obj, false) + "], because the given charset [" + charset + "] is not supported");

}
else {
String msg = e.getMessage();
String appendix = StringUtil.isEmpty(msg, true) ? "" : (", caused by [" + msg + "]");
ae = new ApplicationException("Failed to write to file [" + Caster.toResource(pc, obj, false) + "]" + appendix);

}
ExceptionUtil.initCauseEL(ae, e);
return ae;
}
}
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.1.1.98-SNAPSHOT"/>
<property name="version" value="6.1.1.99-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.1.1.98-SNAPSHOT</version>
<version>6.1.1.99-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 71ba37f

Please sign in to comment.