From 8a35389a2b2a964a665b4df34e6f0c6379d8a982 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 12:02:06 +0300 Subject: [PATCH 01/13] #3735: show file name and line number --- eo-runtime/src/main/java/org/eolang/PhSafe.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index bff4897426..0d5a72d146 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -121,6 +121,14 @@ private static T through(final Action action) { private static String message(final Throwable exp) { final StringBuilder ret = new StringBuilder(0); if (!(exp instanceof ExFailure)) { + final StackTraceElement[] stack = exp.getStackTrace(); + if (stack.length > 0) { + final StackTraceElement last = stack[0]; + ret.append(last.getFileName()); + ret.append(':'); + ret.append(last.getLineNumber()); + ret.append(' '); + } ret.append(exp.getClass().getSimpleName()); } if (exp.getMessage() != null) { From 86ab8a2add9a02831dd08064291a103df8468c41 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 12:15:32 +0300 Subject: [PATCH 02/13] #3735: test --- .../src/test/java/org/eolang/PhSafeTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/eo-runtime/src/test/java/org/eolang/PhSafeTest.java b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java index 903ae44d34..0c62b1a00f 100644 --- a/eo-runtime/src/test/java/org/eolang/PhSafeTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java @@ -57,4 +57,26 @@ void rendersMultiLayeredErrorMessageCorrectly() { ); } + @Test + void showsFileNameAndLineNumber() { + MatcherAssert.assertThat( + "shows file name and line number", + new Dataized( + Assertions.assertThrows( + EOerror.ExError.class, + () -> new PhSafe( + new PhDefault() { + @Override + public Phi take(final String name) { + throw new ExFailure("intentional error"); + } + } + ).take("foo"), + "throws correct class" + ).enclosure() + ).take(String.class), + Matchers.equalTo("intentional error") + ); + } + } From 0449fb20f5f6f0e46b591008cb4310af07c44b75 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 12:18:51 +0300 Subject: [PATCH 03/13] #3735: removed --- eo-runtime/src/main/java/org/eolang/PhSafe.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index 0d5a72d146..76e0efa1b8 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -120,17 +120,6 @@ private static T through(final Action action) { */ private static String message(final Throwable exp) { final StringBuilder ret = new StringBuilder(0); - if (!(exp instanceof ExFailure)) { - final StackTraceElement[] stack = exp.getStackTrace(); - if (stack.length > 0) { - final StackTraceElement last = stack[0]; - ret.append(last.getFileName()); - ret.append(':'); - ret.append(last.getLineNumber()); - ret.append(' '); - } - ret.append(exp.getClass().getSimpleName()); - } if (exp.getMessage() != null) { if (ret.length() > 0) { ret.append(": "); From fed9ce2435f3ee56dcefa5ec248b23f9603e1ff2 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 12:29:20 +0300 Subject: [PATCH 04/13] #3735: dead code --- .../test/java/org/eolang/DataizedTest.java | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/eo-runtime/src/test/java/org/eolang/DataizedTest.java b/eo-runtime/src/test/java/org/eolang/DataizedTest.java index 827d7339a5..81bcbcb9d9 100644 --- a/eo-runtime/src/test/java/org/eolang/DataizedTest.java +++ b/eo-runtime/src/test/java/org/eolang/DataizedTest.java @@ -113,34 +113,6 @@ private static class PhIncorrect extends PhDefault { } } - /** - * Fake Phi with decoration. - * - * @since 0.1.0 - */ - public static class PhiDec extends PhDefault { - - /** - * Ctor. - */ - @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") - PhiDec() { - this.add( - "φ", - new AtOnce( - new AtComposite( - this, - rho -> new PhWith( - new PhCopy(new PhMethod(new Data.ToPhi(2L), "plus")), - 0, - new Data.ToPhi(2L) - ) - ) - ) - ); - } - } - /** * Handler implementation for tests. * From acef35469d8b7b3bbb15946bb16663b28d28aad5 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 12:37:52 +0300 Subject: [PATCH 05/13] #3735: test optimized --- .../test/java/org/eolang/DataizedTest.java | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/eo-runtime/src/test/java/org/eolang/DataizedTest.java b/eo-runtime/src/test/java/org/eolang/DataizedTest.java index 81bcbcb9d9..fed6a1296f 100644 --- a/eo-runtime/src/test/java/org/eolang/DataizedTest.java +++ b/eo-runtime/src/test/java/org/eolang/DataizedTest.java @@ -56,11 +56,22 @@ void logsAllLocationsWithPhSafe() { EOerror.ExError.class, () -> new Dataized( new PhSafe( - new PhLocated(new PhIncorrect(), "foo.bar", 0, 0) + new PhLocated( + new PhMethod( + new PhDefault() { + @Override + public Phi take(final String name) { + throw new ExFailure("intentional error"); + } + }, + "xyz" + ), + "foo.bar", 0, 0 + ) ), log ).take(), - "it is expected to fail with ExFailure exception" + "it is expected to fail with and exception" ); log.setLevel(before); log.removeHandler(hnd); @@ -69,10 +80,8 @@ void logsAllLocationsWithPhSafe() { logs.get(0).getMessage(), Matchers.allOf( Matchers.containsString("1) Error in"), - Matchers.containsString("2) There's no"), - Matchers.containsString("3)"), Matchers.containsString("at foo.bar:0:0"), - Matchers.containsString("no \"Δ\" in the object of") + Matchers.containsString("intentional error") ) ); } @@ -92,27 +101,6 @@ void failsWhenError() { ); } - /** - * Fake Phi failing when dataized. - * @since 0.1.0 - */ - private static class PhIncorrect extends PhDefault { - - /** - * Ctor. - */ - @SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors") - PhIncorrect() { - this.add( - "Δ", - new AtComposite( - this, - rho -> Phi.Φ - ) - ); - } - } - /** * Handler implementation for tests. * From 88ce6535bf21ef430ce20586ece39d490810d711 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 14:25:44 +0300 Subject: [PATCH 06/13] PhSafe removed --- .../org/eolang/maven/pre/to-java.xsl | 4 +- .../java/EOorg/EOeolang/EObytes$EOslice.java | 6 +- .../src/main/java/EOorg/EOeolang/EOerror.java | 18 +++ .../src/main/java/EOorg/EOeolang/EOtry.java | 15 +- .../src/main/java/org/eolang/Expect.java | 4 +- .../src/main/java/org/eolang/PhLocated.java | 42 ++--- .../src/main/java/org/eolang/PhSafe.java | 151 ------------------ .../EOorg/EOeolang/EObytesEOsliceTest.java | 10 +- .../test/java/EOorg/EOeolang/EOtryTest.java | 33 ++-- .../test/java/org/eolang/DataizedTest.java | 24 ++- .../test/java/org/eolang/PhDefaultTest.java | 10 +- .../test/java/org/eolang/PhLocatedTest.java | 52 +++++- .../src/test/java/org/eolang/PhSafeTest.java | 82 ---------- 13 files changed, 135 insertions(+), 316 deletions(-) delete mode 100644 eo-runtime/src/main/java/org/eolang/PhSafe.java delete mode 100644 eo-runtime/src/test/java/org/eolang/PhSafeTest.java diff --git a/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl b/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl index ff60feea01..ade1512e22 100644 --- a/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl +++ b/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl @@ -538,9 +538,9 @@ SOFTWARE. new Dataized( - new PhSafe(new + new - ()) + () ).asBool() diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EObytes$EOslice.java b/eo-runtime/src/main/java/EOorg/EOeolang/EObytes$EOslice.java index cf99e58841..57376d0bbb 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EObytes$EOslice.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EObytes$EOslice.java @@ -77,9 +77,11 @@ public Phi lambda() { .must(integer -> integer >= 0) .otherwise("must be a positive integer") .it(); - final byte[] array = new Dataized(this.take(Attr.RHO)).take(); return new Data.ToPhi( - Arrays.copyOfRange(array, start, start + length) + Arrays.copyOfRange( + new Dataized(this.take(Attr.RHO)).take(), + start, start + length + ) ); } } diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOerror.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOerror.java index c1dcf96226..aaf712f165 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOerror.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOerror.java @@ -99,6 +99,15 @@ public ExError(final Phi enclosure) { this(enclosure, Collections.emptyList()); } + /** + * Ctor. + * @param cause Previous error + * @param message New message + */ + public ExError(final Phi cause, final String message) { + this(cause, Collections.singletonList(message)); + } + /** * Ctor. * @param cause Previous error @@ -119,6 +128,15 @@ public ExError(final Phi enclosure, final Collection before) { this.trace = before; } + @Override + public String toString() { + return String.format( + "%s +%s", + super.toString(), + this.trace.size() + ); + } + /** * Take it. * @return The enclosed object diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java index 536592bbfa..2df2a29419 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java @@ -32,8 +32,9 @@ import org.eolang.Atom; import org.eolang.Data; import org.eolang.Dataized; +import org.eolang.PhCopy; import org.eolang.PhDefault; -import org.eolang.PhSafe; +import org.eolang.PhWith; import org.eolang.Phi; import org.eolang.XmirObject; @@ -59,11 +60,15 @@ public EOtry() { public Phi lambda() { byte[] result; try { - result = new Dataized(new PhSafe(this.take("main"))).take(); + result = new Dataized(this.take("main")).take(); } catch (final EOerror.ExError ex) { - final Phi caught = this.take("catch").copy(); - caught.put(0, ex.enclosure()); - result = new Dataized(caught).take(); + result = new Dataized( + new PhWith( + new PhCopy(this.take("catch")), + 0, + ex.enclosure() + ) + ).take(); } finally { new Dataized(this.take("finally")).take(); } diff --git a/eo-runtime/src/main/java/org/eolang/Expect.java b/eo-runtime/src/main/java/org/eolang/Expect.java index 2424138e1c..de9ff53bd1 100644 --- a/eo-runtime/src/main/java/org/eolang/Expect.java +++ b/eo-runtime/src/main/java/org/eolang/Expect.java @@ -98,7 +98,7 @@ public Expect otherwise(final String message) { return this.sup.get(); } catch (final ExFailure ex) { throw new ExFailure( - String.format("%s %s", this.subject, message), + String.format("%s %s %s", this.subject, ex.getMessage(), message), ex ); } @@ -118,7 +118,7 @@ public Expect must(final Function fun) { final T ret = this.sup.get(); if (!fun.apply(ret)) { throw new ExFailure( - String.format("%s (%s)", this.subject, ret) + String.format("(%s)", ret) ); } return ret; diff --git a/eo-runtime/src/main/java/org/eolang/PhLocated.java b/eo-runtime/src/main/java/org/eolang/PhLocated.java index fff7d22012..0fea01b836 100644 --- a/eo-runtime/src/main/java/org/eolang/PhLocated.java +++ b/eo-runtime/src/main/java/org/eolang/PhLocated.java @@ -25,8 +25,6 @@ package org.eolang; import EOorg.EOeolang.EOerror; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; /** * An object with coordinates (line and position). @@ -61,6 +59,16 @@ public final class PhLocated implements Phi, Atom { */ private final String location; + /** + * Ctor. + * + * @param phi The object + * @checkstyle ParameterNumberCheck (5 lines) + */ + public PhLocated(final Phi phi) { + this(phi, "unknown", 0, 0); + } + /** * Ctor. * @@ -174,32 +182,12 @@ private T through(final Action action, final String suffix) { throw new ExReadOnly(this.label(suffix), ex); } catch (final EOerror.ExError ex) { throw new EOerror.ExError(ex, this.label(suffix)); - } catch (final ExAbstract | Error ex) { - throw new ExFailure(this.label(suffix), ex); - } catch (final RuntimeException ex) { - throw this.wrap(ex, suffix); - } - } - - /** - * Wrap the exception into a new one. - * @param cause Original - * @param suffix Te suffix - * @return New exception - */ - private RuntimeException wrap(final RuntimeException cause, - final String suffix) { - final String label = this.label(suffix); - RuntimeException ret; - try { - final Constructor ctor = - cause.getClass().getConstructor(String.class, Throwable.class); - ret = ctor.newInstance(label, cause); - } catch (final NoSuchMethodException | InstantiationException - | IllegalAccessException | InvocationTargetException ex) { - ret = new ExFailure(label, cause); + } catch (final RuntimeException | Error ex) { + throw new EOerror.ExError( + new Data.ToPhi(ex.getMessage()), + this.label(suffix) + ); } - return ret; } /** diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java deleted file mode 100644 index 76e0efa1b8..0000000000 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2024 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.eolang; - -import EOorg.EOeolang.EOerror; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - -/** - * It catches {@link ExFailure} and - * throws {@link EOerror.ExError}. - * - * @since 0.26 - */ -@SuppressWarnings("PMD.TooManyMethods") -public final class PhSafe implements Phi { - - /** - * The original. - */ - private final Phi origin; - - /** - * Ctor. - * @param phi The object - */ - public PhSafe(final Phi phi) { - this.origin = phi; - } - - @Override - public boolean equals(final Object obj) { - return PhSafe.through(() -> this.origin.equals(obj)); - } - - @Override - public int hashCode() { - return PhSafe.through(this.origin::hashCode); - } - - @Override - public Phi copy() { - return PhSafe.through(() -> new PhSafe(this.origin.copy())); - } - - @Override - public Phi take(final String name) { - return PhSafe.through(() -> new PhSafe(this.origin.take(name))); - } - - @Override - public boolean put(final int pos, final Phi object) { - return PhSafe.through(() -> this.origin.put(pos, object)); - } - - @Override - public boolean put(final String name, final Phi object) { - return PhSafe.through(() -> this.origin.put(name, object)); - } - - @Override - public String locator() { - return PhSafe.through(this.origin::locator); - } - - @Override - public String forma() { - return PhSafe.through(this.origin::forma); - } - - @Override - public byte[] delta() { - return PhSafe.through(this.origin::delta); - } - - /** - * Helper, for other methods. - * @param action The action - * @param Type of result - * @return Result - */ - private static T through(final Action action) { - try { - return action.act(); - } catch (final ExFailure ex) { - throw new EOerror.ExError( - new Data.ToPhi(PhSafe.message(ex)), - PhSafe.messages(ex) - ); - } - } - - /** - * Make a message from an exception. - * @param exp The exception. - * @return Message. - */ - private static String message(final Throwable exp) { - final StringBuilder ret = new StringBuilder(0); - if (exp.getMessage() != null) { - if (ret.length() > 0) { - ret.append(": "); - } - ret.append(exp.getMessage().replace("%", "%%")); - } - if (exp.getCause() != null) { - ret.setLength(0); - ret.append(PhSafe.message(exp.getCause())); - } - return ret.toString(); - } - - /** - * Make a chain of messages from an exception and its causes. - * @param exp The exception - * @return Messages - */ - private static List messages(final Throwable exp) { - final List msgs = new LinkedList<>(); - if (exp != null) { - msgs.add(exp.getMessage()); - msgs.addAll(PhSafe.messages(exp.getCause())); - Collections.reverse(msgs); - } - return msgs; - } - -} diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EObytesEOsliceTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EObytesEOsliceTest.java index 3e1d6a9731..2def3adcf0 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EObytesEOsliceTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EObytesEOsliceTest.java @@ -32,7 +32,6 @@ import java.io.PrintWriter; import org.eolang.Data; import org.eolang.Dataized; -import org.eolang.ExFailure; import org.eolang.PhWith; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -71,8 +70,8 @@ void takesLegalSlice() { @Test void takesWrongSlice() { - final ExFailure exp = Assertions.assertThrows( - ExFailure.class, + final EOerror.ExError exp = Assertions.assertThrows( + EOerror.ExError.class, () -> new Dataized( new PhWith( new PhWith( @@ -96,10 +95,7 @@ void takesWrongSlice() { MatcherAssert.assertThat( "error message is correct", baos.toString(), - Matchers.allOf( - Matchers.containsString("the 'len' attribute must be a positive integer"), - Matchers.containsString("the 'len' attribute (-5)") - ) + Matchers.containsString("the 'len' attribute (-5) must be a positive integer") ); } diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java index 6625acbe7d..6fceedb04e 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java @@ -36,7 +36,7 @@ import org.eolang.Dataized; import org.eolang.ExFailure; import org.eolang.PhDefault; -import org.eolang.PhSafe; +import org.eolang.PhLocated; import org.eolang.PhWith; import org.eolang.Phi; import org.hamcrest.MatcherAssert; @@ -53,13 +53,13 @@ final class EOtryTest { @Test void catchesException() { MatcherAssert.assertThat( - AtCompositeTest.TO_ADD_MESSAGE, + "catches exception", new Dataized( new PhWith( new PhWith( new PhWith( new EOtry(), - 0, new PhSafe(new Broken()) + 0, new PhLocated(new Broken()) ), 1, new Catcher() ), @@ -73,20 +73,21 @@ void catchesException() { @Test void usesCatcherOutput() { - final Phi body = new PhWith( - new PhWith( - new PhWith( - new EOtry(), - 0, new PhSafe(new Broken()) - ), - 1, new Catcher() - ), - 2, - new Data.ToPhi(true) - ); MatcherAssert.assertThat( - AtCompositeTest.TO_ADD_MESSAGE, - new Dataized(body).asString(), + "uses catcher's output", + new Dataized( + new PhWith( + new PhWith( + new PhWith( + new EOtry(), + 0, new PhLocated(new Broken()) + ), + 1, new Catcher() + ), + 2, + new Data.ToPhi(true) + ) + ).asString(), Matchers.containsString("it is broken") ); } diff --git a/eo-runtime/src/test/java/org/eolang/DataizedTest.java b/eo-runtime/src/test/java/org/eolang/DataizedTest.java index fed6a1296f..be5f72dee6 100644 --- a/eo-runtime/src/test/java/org/eolang/DataizedTest.java +++ b/eo-runtime/src/test/java/org/eolang/DataizedTest.java @@ -55,19 +55,17 @@ void logsAllLocationsWithPhSafe() { Assertions.assertThrows( EOerror.ExError.class, () -> new Dataized( - new PhSafe( - new PhLocated( - new PhMethod( - new PhDefault() { - @Override - public Phi take(final String name) { - throw new ExFailure("intentional error"); - } - }, - "xyz" - ), - "foo.bar", 0, 0 - ) + new PhLocated( + new PhMethod( + new PhDefault() { + @Override + public Phi take(final String name) { + throw new IllegalStateException("intentional error"); + } + }, + "xyz" + ), + "foo.bar", 0, 0 ), log ).take(), diff --git a/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java b/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java index cbef982162..7f923693dd 100644 --- a/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java @@ -76,7 +76,7 @@ void comparesTwoCopies() { @Test void doesNotHaveRhoWhenFormed() { - final Phi phi = new PhSafe(new PhDefaultTest.Int()); + final Phi phi = new PhLocated(new PhDefaultTest.Int()); Assertions.assertThrows( ExAbstract.class, () -> phi.take(Attr.RHO), @@ -95,7 +95,7 @@ void setsRhoAfterDispatch() { @Test void doesNotHaveRhoAfterCopying() { - final Phi phi = new PhSafe(new PhDefaultTest.Int().copy()); + final Phi phi = new PhLocated(new PhDefaultTest.Int().copy()); Assertions.assertThrows( ExAbstract.class, () -> phi.take(Attr.RHO), @@ -215,7 +215,7 @@ void doesNotCopyRhoWhileDispatch() { @Test void copiesUnsetVoidAttribute() { - final Phi phi = new PhSafe(new PhDefaultTest.Int()); + final Phi phi = new PhLocated(new PhDefaultTest.Int()); final Phi copy = phi.copy(); Assertions.assertThrows( ExAbstract.class, @@ -261,7 +261,7 @@ void doesNotCopyContextAttributeWithRho() { @Test void hasAccessToDependentOnContextAttribute() { - final Phi phi = new PhSafe(new PhDefaultTest.Int().copy()); + final Phi phi = new PhLocated(new PhDefaultTest.Int().copy()); Assertions.assertThrows( ExAbstract.class, () -> phi.take(Attr.PHI), @@ -315,7 +315,7 @@ void createsDifferentPhiInParallel() { void failsGracefullyOnMissingAttribute() { Assertions.assertThrows( ExAbstract.class, - () -> new PhSafe(new Data.ToPhi("Hey")).take("missing-attr"), + () -> new PhLocated(new Data.ToPhi("Hey")).take("missing-attr"), AtCompositeTest.TO_ADD_MESSAGE ); } diff --git a/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java b/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java index 3db7275b4b..1e28c320f1 100644 --- a/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java @@ -23,6 +23,7 @@ */ package org.eolang; +import EOorg.EOeolang.EOerror; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; @@ -50,21 +51,64 @@ void catchesRuntimeException() { MatcherAssert.assertThat( "rethrows correctly", Assertions.assertThrows( - IllegalArgumentException.class, + EOerror.ExError.class, () -> new PhLocated( new PhDefault() { @Override public byte[] delta() { throw new IllegalArgumentException("oops"); } - }, - "foobar", 10, 20 + } ).delta(), "throws correct class" + ).messages(), + Matchers.hasItem( + Matchers.containsString("Error in \"?.Δ\" at unknown:0:0") + ) + ); + } + + @Test + void rendersMultiLayeredErrorMessageCorrectly() { + MatcherAssert.assertThat( + "rethrows correctly", + Assertions.assertThrows( + EOerror.ExError.class, + () -> new PhLocated( + new PhWith( + new EOerror(), + "message", + new Data.ToPhi("oops") + ) + ).take("foo"), + "throws correct class" ), Matchers.hasToString( - Matchers.containsString("Error in \"?.Δ\" at foobar:10:20") + Matchers.containsString("Δ = [0x6F6F7073-] = \"oops\"") ) ); } + + @Test + void showsFileNameAndLineNumber() { + MatcherAssert.assertThat( + "shows file name and line number", + new Dataized( + Assertions.assertThrows( + EOerror.ExError.class, + () -> new PhLocated( + new PhDefault() { + @Override + public Phi take(final String name) { + throw new IllegalArgumentException("intentional error"); + } + } + ).take("foo"), + "throws correct class" + ).enclosure() + ).take(String.class), + Matchers.equalTo("intentional error") + ); + } + } diff --git a/eo-runtime/src/test/java/org/eolang/PhSafeTest.java b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java deleted file mode 100644 index 0c62b1a00f..0000000000 --- a/eo-runtime/src/test/java/org/eolang/PhSafeTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2016-2024 Objectionary.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package org.eolang; - -import EOorg.EOeolang.EOerror; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -/** - * Test case for {@link PhSafe}. - * - * @since 0.42 - */ -final class PhSafeTest { - - @Test - void rendersMultiLayeredErrorMessageCorrectly() { - MatcherAssert.assertThat( - "rethrows correctly", - Assertions.assertThrows( - EOerror.ExError.class, - () -> new PhSafe( - new PhWith( - new EOerror(), - "message", - new Data.ToPhi("oops") - ) - ).take("foo"), - "throws correct class" - ), - Matchers.hasToString( - Matchers.containsString("Δ = [0x6F6F7073-] = \"oops\"") - ) - ); - } - - @Test - void showsFileNameAndLineNumber() { - MatcherAssert.assertThat( - "shows file name and line number", - new Dataized( - Assertions.assertThrows( - EOerror.ExError.class, - () -> new PhSafe( - new PhDefault() { - @Override - public Phi take(final String name) { - throw new ExFailure("intentional error"); - } - } - ).take("foo"), - "throws correct class" - ).enclosure() - ).take(String.class), - Matchers.equalTo("intentional error") - ); - } - -} From c61966885bdf209bb9135586b09899fc85437888 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 16:01:46 +0300 Subject: [PATCH 07/13] #3735: fix --- eo-runtime/src/main/java/org/eolang/PhLocated.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/PhLocated.java b/eo-runtime/src/main/java/org/eolang/PhLocated.java index 0fea01b836..f92d5f71c0 100644 --- a/eo-runtime/src/main/java/org/eolang/PhLocated.java +++ b/eo-runtime/src/main/java/org/eolang/PhLocated.java @@ -176,10 +176,6 @@ private T through(final Action action) { private T through(final Action action, final String suffix) { try { return action.act(); - } catch (final ExUnset ex) { - throw new ExUnset(this.label(suffix), ex); - } catch (final ExReadOnly ex) { - throw new ExReadOnly(this.label(suffix), ex); } catch (final EOerror.ExError ex) { throw new EOerror.ExError(ex, this.label(suffix)); } catch (final RuntimeException | Error ex) { From c2b6658669c6a79877e35e124b9da55d69d6cb68 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 16:08:38 +0300 Subject: [PATCH 08/13] #3735: rename to PhSafe --- .../resources/org/eolang/maven/pre/to-java.xsl | 2 +- .../org/eolang/maven/packs/locators-to-java.yaml | 16 ++++++++-------- .../org/eolang/{PhLocated.java => PhSafe.java} | 10 +++++----- .../src/test/java/EOorg/EOeolang/EOtryTest.java | 6 +++--- .../src/test/java/org/eolang/DataizedTest.java | 2 +- .../src/test/java/org/eolang/PhDefaultTest.java | 10 +++++----- .../{PhLocatedTest.java => PhSafeTest.java} | 12 ++++++------ eo-runtime/src/test/java/org/eolang/PhiTest.java | 2 +- 8 files changed, 30 insertions(+), 30 deletions(-) rename eo-runtime/src/main/java/org/eolang/{PhLocated.java => PhSafe.java} (94%) rename eo-runtime/src/test/java/org/eolang/{PhLocatedTest.java => PhSafeTest.java} (92%) diff --git a/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl b/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl index ade1512e22..f8930869c1 100644 --- a/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl +++ b/eo-maven-plugin/src/main/resources/org/eolang/maven/pre/to-java.xsl @@ -404,7 +404,7 @@ SOFTWARE. - = new PhLocated( + = new PhSafe( , " diff --git a/eo-maven-plugin/src/test/resources/org/eolang/maven/packs/locators-to-java.yaml b/eo-maven-plugin/src/test/resources/org/eolang/maven/packs/locators-to-java.yaml index c191579e9b..dacf24e743 100644 --- a/eo-maven-plugin/src/test/resources/org/eolang/maven/packs/locators-to-java.yaml +++ b/eo-maven-plugin/src/test/resources/org/eolang/maven/packs/locators-to-java.yaml @@ -32,14 +32,14 @@ sheets: - /org/eolang/parser/blank-xsd-schema.xsl asserts: - /program[not(errors)] - - //java[contains(text(), 'new PhLocated(ret, "scenario", 3, 2, "Φ.foo.φ")')] - - //java[contains(text(), 'new PhLocated(ret_base, "scenario", 6, 4, "Φ.foo.other.φ.ρ")')] - - //java[contains(text(), 'new PhLocated(ret, "scenario", 6, 6, "Φ.foo.other.φ")')] - - //java[contains(text(), 'new PhLocated(ret_1, "scenario", 6, 12, "Φ.foo.other.φ.α0")')] - - //java[contains(text(), 'new PhLocated(ret_base, "scenario", 10, 2, "Φ.bar.φ.ρ")')] - - //java[contains(text(), 'new PhLocated(ret, "scenario", 10, 4, "Φ.bar.φ")')] - - //java[contains(text(), 'new PhLocated(ret_1, "scenario", 10, 10, "Φ.bar.φ.α0")')] - - //java[contains(text(), 'new PhLocated(ret, "scenario", 11, 2, "Φ.bar.five")')] + - //java[contains(text(), 'new PhSafe(ret, "scenario", 3, 2, "Φ.foo.φ")')] + - //java[contains(text(), 'new PhSafe(ret_base, "scenario", 6, 4, "Φ.foo.other.φ.ρ")')] + - //java[contains(text(), 'new PhSafe(ret, "scenario", 6, 6, "Φ.foo.other.φ")')] + - //java[contains(text(), 'new PhSafe(ret_1, "scenario", 6, 12, "Φ.foo.other.φ.α0")')] + - //java[contains(text(), 'new PhSafe(ret_base, "scenario", 10, 2, "Φ.bar.φ.ρ")')] + - //java[contains(text(), 'new PhSafe(ret, "scenario", 10, 4, "Φ.bar.φ")')] + - //java[contains(text(), 'new PhSafe(ret_1, "scenario", 10, 10, "Φ.bar.φ.α0")')] + - //java[contains(text(), 'new PhSafe(ret, "scenario", 11, 2, "Φ.bar.five")')] input: | # No comments. [] > foo diff --git a/eo-runtime/src/main/java/org/eolang/PhLocated.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java similarity index 94% rename from eo-runtime/src/main/java/org/eolang/PhLocated.java rename to eo-runtime/src/main/java/org/eolang/PhSafe.java index f92d5f71c0..1d151b437c 100644 --- a/eo-runtime/src/main/java/org/eolang/PhLocated.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -32,7 +32,7 @@ * @since 0.21 */ @SuppressWarnings("PMD.TooManyMethods") -public final class PhLocated implements Phi, Atom { +public final class PhSafe implements Phi, Atom { /** * The original. @@ -65,7 +65,7 @@ public final class PhLocated implements Phi, Atom { * @param phi The object * @checkstyle ParameterNumberCheck (5 lines) */ - public PhLocated(final Phi phi) { + public PhSafe(final Phi phi) { this(phi, "unknown", 0, 0); } @@ -78,7 +78,7 @@ public PhLocated(final Phi phi) { * @param pos Position * @checkstyle ParameterNumberCheck (5 lines) */ - public PhLocated(final Phi phi, final String prg, final int lne, final int pos) { + public PhSafe(final Phi phi, final String prg, final int lne, final int pos) { this(phi, prg, lne, pos, "?"); } @@ -92,7 +92,7 @@ public PhLocated(final Phi phi, final String prg, final int lne, final int pos) * @param loc Location * @checkstyle ParameterNumberCheck (5 lines) */ - public PhLocated(final Phi phi, final String prg, final int lne, + public PhSafe(final Phi phi, final String prg, final int lne, final int pos, final String loc) { this.origin = phi; this.program = prg; @@ -113,7 +113,7 @@ public int hashCode() { @Override public Phi copy() { - return new PhLocated( + return new PhSafe( this.origin.copy(), this.program, this.line, this.position, this.location ); diff --git a/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java b/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java index 6fceedb04e..02fc3562a7 100644 --- a/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java +++ b/eo-runtime/src/test/java/EOorg/EOeolang/EOtryTest.java @@ -36,7 +36,7 @@ import org.eolang.Dataized; import org.eolang.ExFailure; import org.eolang.PhDefault; -import org.eolang.PhLocated; +import org.eolang.PhSafe; import org.eolang.PhWith; import org.eolang.Phi; import org.hamcrest.MatcherAssert; @@ -59,7 +59,7 @@ void catchesException() { new PhWith( new PhWith( new EOtry(), - 0, new PhLocated(new Broken()) + 0, new PhSafe(new Broken()) ), 1, new Catcher() ), @@ -80,7 +80,7 @@ void usesCatcherOutput() { new PhWith( new PhWith( new EOtry(), - 0, new PhLocated(new Broken()) + 0, new PhSafe(new Broken()) ), 1, new Catcher() ), diff --git a/eo-runtime/src/test/java/org/eolang/DataizedTest.java b/eo-runtime/src/test/java/org/eolang/DataizedTest.java index be5f72dee6..a6e4a101df 100644 --- a/eo-runtime/src/test/java/org/eolang/DataizedTest.java +++ b/eo-runtime/src/test/java/org/eolang/DataizedTest.java @@ -55,7 +55,7 @@ void logsAllLocationsWithPhSafe() { Assertions.assertThrows( EOerror.ExError.class, () -> new Dataized( - new PhLocated( + new PhSafe( new PhMethod( new PhDefault() { @Override diff --git a/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java b/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java index 7f923693dd..cbef982162 100644 --- a/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhDefaultTest.java @@ -76,7 +76,7 @@ void comparesTwoCopies() { @Test void doesNotHaveRhoWhenFormed() { - final Phi phi = new PhLocated(new PhDefaultTest.Int()); + final Phi phi = new PhSafe(new PhDefaultTest.Int()); Assertions.assertThrows( ExAbstract.class, () -> phi.take(Attr.RHO), @@ -95,7 +95,7 @@ void setsRhoAfterDispatch() { @Test void doesNotHaveRhoAfterCopying() { - final Phi phi = new PhLocated(new PhDefaultTest.Int().copy()); + final Phi phi = new PhSafe(new PhDefaultTest.Int().copy()); Assertions.assertThrows( ExAbstract.class, () -> phi.take(Attr.RHO), @@ -215,7 +215,7 @@ void doesNotCopyRhoWhileDispatch() { @Test void copiesUnsetVoidAttribute() { - final Phi phi = new PhLocated(new PhDefaultTest.Int()); + final Phi phi = new PhSafe(new PhDefaultTest.Int()); final Phi copy = phi.copy(); Assertions.assertThrows( ExAbstract.class, @@ -261,7 +261,7 @@ void doesNotCopyContextAttributeWithRho() { @Test void hasAccessToDependentOnContextAttribute() { - final Phi phi = new PhLocated(new PhDefaultTest.Int().copy()); + final Phi phi = new PhSafe(new PhDefaultTest.Int().copy()); Assertions.assertThrows( ExAbstract.class, () -> phi.take(Attr.PHI), @@ -315,7 +315,7 @@ void createsDifferentPhiInParallel() { void failsGracefullyOnMissingAttribute() { Assertions.assertThrows( ExAbstract.class, - () -> new PhLocated(new Data.ToPhi("Hey")).take("missing-attr"), + () -> new PhSafe(new Data.ToPhi("Hey")).take("missing-attr"), AtCompositeTest.TO_ADD_MESSAGE ); } diff --git a/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java similarity index 92% rename from eo-runtime/src/test/java/org/eolang/PhLocatedTest.java rename to eo-runtime/src/test/java/org/eolang/PhSafeTest.java index 1e28c320f1..5712b09715 100644 --- a/eo-runtime/src/test/java/org/eolang/PhLocatedTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java @@ -30,15 +30,15 @@ import org.junit.jupiter.api.Test; /** - * Test case for {@link PhLocatedTest}. + * Test case for {@link PhSafeTest}. * * @since 0.36.0 */ -final class PhLocatedTest { +final class PhSafeTest { @Test void savesLocationAfterCopying() { - final Phi located = new PhLocated(new Data.ToPhi(0L), "foo", 123, 124, "qwerty"); + final Phi located = new PhSafe(new Data.ToPhi(0L), "foo", 123, 124, "qwerty"); MatcherAssert.assertThat( "saves location", located.copy().locator(), @@ -52,7 +52,7 @@ void catchesRuntimeException() { "rethrows correctly", Assertions.assertThrows( EOerror.ExError.class, - () -> new PhLocated( + () -> new PhSafe( new PhDefault() { @Override public byte[] delta() { @@ -74,7 +74,7 @@ void rendersMultiLayeredErrorMessageCorrectly() { "rethrows correctly", Assertions.assertThrows( EOerror.ExError.class, - () -> new PhLocated( + () -> new PhSafe( new PhWith( new EOerror(), "message", @@ -96,7 +96,7 @@ void showsFileNameAndLineNumber() { new Dataized( Assertions.assertThrows( EOerror.ExError.class, - () -> new PhLocated( + () -> new PhSafe( new PhDefault() { @Override public Phi take(final String name) { diff --git a/eo-runtime/src/test/java/org/eolang/PhiTest.java b/eo-runtime/src/test/java/org/eolang/PhiTest.java index 6761f4dbc7..ca5aa723f9 100644 --- a/eo-runtime/src/test/java/org/eolang/PhiTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhiTest.java @@ -99,7 +99,7 @@ void takesDirectly() { void getsLocation() { MatcherAssert.assertThat( AtCompositeTest.TO_ADD_MESSAGE, - new PhLocated( + new PhSafe( Phi.Φ, "foobar", 123, From fe4d783e588a5e56cf2a7a9e3126c57b6085ec00 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 16:15:12 +0300 Subject: [PATCH 09/13] #3735: disable invoker --- eo-maven-plugin/pom.xml | 4 +++- eo-runtime/src/main/java/org/eolang/PhSafe.java | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/eo-maven-plugin/pom.xml b/eo-maven-plugin/pom.xml index 17f5076eaa..b7cc130816 100644 --- a/eo-maven-plugin/pom.xml +++ b/eo-maven-plugin/pom.xml @@ -301,7 +301,9 @@ SOFTWARE. ${skipTests} ${skipTests} - + + fibonacci/pom.xml + diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index 1d151b437c..415b859820 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -27,7 +27,15 @@ import EOorg.EOeolang.EOerror; /** - * An object with coordinates (line and position). + * An object with coordinates (line and position) and a safe + * processing of any runtime errors. + * + *

It is used to wrap any object and provide a safe processing + * of any runtime errors. It is used in the EO runtime to provide + * a safe processing of any runtime errors in the EO code. If, in any + * method invocation, a runtime error occurs, it is caught and wrapped + * into {@link EOerror.ExError} with the location of the error in the + * EO code.

* * @since 0.21 */ From f9d7a3c68bde69bad48610b93a467251454af7f8 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 16:46:29 +0300 Subject: [PATCH 10/13] #3735: show line number --- .../src/main/java/org/eolang/PhSafe.java | 23 ++++++++++++++++++- .../src/test/java/org/eolang/PhSafeTest.java | 6 ++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index 415b859820..db1329bab4 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -174,6 +174,11 @@ private T through(final Action action) { /** * Helper, for other methods. + * + *

No matter what happens inside the {@code action}, only + * an instance of {@link EOerror.ExError} may be thrown out + * of this method.

+ * * @param action The action * @param suffix The suffix to add to the label * @param Type of result @@ -186,11 +191,27 @@ private T through(final Action action, final String suffix) { return action.act(); } catch (final EOerror.ExError ex) { throw new EOerror.ExError(ex, this.label(suffix)); - } catch (final RuntimeException | Error ex) { + } catch (final ExAbstract ex) { throw new EOerror.ExError( new Data.ToPhi(ex.getMessage()), this.label(suffix) ); + } catch (final RuntimeException | Error ex) { + final StringBuilder msg = new StringBuilder(0); + final StackTraceElement[] stack = ex.getStackTrace(); + if (stack != null && stack.length > 0) { + final StackTraceElement last = stack[0]; + msg.append(last.getFileName()).append(':') + .append(last.getLineNumber()).append(':') + .append(' '); + } + msg.append(ex.getClass().getSimpleName()) + .append(": ") + .append(ex.getMessage()); + throw new EOerror.ExError( + new Data.ToPhi(msg.toString()), + this.label(suffix) + ); } } diff --git a/eo-runtime/src/test/java/org/eolang/PhSafeTest.java b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java index 5712b09715..e8360630c4 100644 --- a/eo-runtime/src/test/java/org/eolang/PhSafeTest.java +++ b/eo-runtime/src/test/java/org/eolang/PhSafeTest.java @@ -107,7 +107,11 @@ public Phi take(final String name) { "throws correct class" ).enclosure() ).take(String.class), - Matchers.equalTo("intentional error") + Matchers.allOf( + Matchers.startsWith("PhSafeTest.java:"), + Matchers.containsString("IllegalArgumentException"), + Matchers.containsString("intentional error") + ) ); } From e89029367ca7cff5ede187b5a757e47a0374eeae Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 16:51:58 +0300 Subject: [PATCH 11/13] #3735: fix --- eo-runtime/src/main/java/org/eolang/PhSafe.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index db1329bab4..6860dfbbaa 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -185,7 +185,7 @@ private T through(final Action action) { * @return Result * @checkstyle IllegalCatchCheck (20 lines) */ - @SuppressWarnings("PMD.AvoidCatchingGenericException") + @SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.PreserveStackTrace"}) private T through(final Action action, final String suffix) { try { return action.act(); @@ -201,9 +201,10 @@ private T through(final Action action, final String suffix) { final StackTraceElement[] stack = ex.getStackTrace(); if (stack != null && stack.length > 0) { final StackTraceElement last = stack[0]; - msg.append(last.getFileName()).append(':') - .append(last.getLineNumber()).append(':') - .append(' '); + msg.append(last.getFileName()) + .append(':') + .append(last.getLineNumber()) + .append(": "); } msg.append(ex.getClass().getSimpleName()) .append(": ") From 9e9d80270b3fe8a383b1072eaeb7a5caf1f69dc2 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 17:03:08 +0300 Subject: [PATCH 12/13] #3735: catch Throwable --- eo-runtime/src/main/java/org/eolang/PhSafe.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eo-runtime/src/main/java/org/eolang/PhSafe.java b/eo-runtime/src/main/java/org/eolang/PhSafe.java index 6860dfbbaa..c15c363160 100644 --- a/eo-runtime/src/main/java/org/eolang/PhSafe.java +++ b/eo-runtime/src/main/java/org/eolang/PhSafe.java @@ -185,7 +185,7 @@ private T through(final Action action) { * @return Result * @checkstyle IllegalCatchCheck (20 lines) */ - @SuppressWarnings({"PMD.AvoidCatchingGenericException", "PMD.PreserveStackTrace"}) + @SuppressWarnings({"PMD.AvoidCatchingThrowable", "PMD.PreserveStackTrace"}) private T through(final Action action, final String suffix) { try { return action.act(); @@ -196,7 +196,7 @@ private T through(final Action action, final String suffix) { new Data.ToPhi(ex.getMessage()), this.label(suffix) ); - } catch (final RuntimeException | Error ex) { + } catch (final Throwable ex) { final StringBuilder msg = new StringBuilder(0); final StackTraceElement[] stack = ex.getStackTrace(); if (stack != null && stack.length > 0) { From 219b645469f98ef114aec614834a529886b2eb89 Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Mon, 23 Dec 2024 19:49:59 +0300 Subject: [PATCH 13/13] #3735: reverted --- eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java index 2df2a29419..654e723948 100644 --- a/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java +++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOtry.java @@ -32,9 +32,7 @@ import org.eolang.Atom; import org.eolang.Data; import org.eolang.Dataized; -import org.eolang.PhCopy; import org.eolang.PhDefault; -import org.eolang.PhWith; import org.eolang.Phi; import org.eolang.XmirObject; @@ -62,13 +60,9 @@ public Phi lambda() { try { result = new Dataized(this.take("main")).take(); } catch (final EOerror.ExError ex) { - result = new Dataized( - new PhWith( - new PhCopy(this.take("catch")), - 0, - ex.enclosure() - ) - ).take(); + final Phi catcher = this.take("catch").copy(); + catcher.put(0, ex.enclosure()); + result = new Dataized(catcher).take(); } finally { new Dataized(this.take("finally")).take(); }