Skip to content

Commit

Permalink
Merge pull request #3660 from objectionary/3659
Browse files Browse the repository at this point in the history
show file name in logs when fails
  • Loading branch information
yegor256 authored Dec 13, 2024
2 parents e6c55c7 + 7e335c0 commit 13e7eeb
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,9 @@ SOFTWARE.
<xsl:value-of select="$name"/>
<xsl:text> = new PhLocated(</xsl:text>
<xsl:value-of select="$name"/>
<xsl:text>, </xsl:text>
<xsl:text>, "</xsl:text>
<xsl:value-of select="/program/@name"/>
<xsl:text>", </xsl:text>
<xsl:value-of select="@line"/>
<xsl:text>, </xsl:text>
<xsl:value-of select="@pos"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@

/**
* Test case for {@link OptimizeMojo}.
*
* @since 0.1
*/
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ sheets:
- /org/eolang/parser/blank-xsd-schema.xsl
asserts:
- /program[not(errors)]
- //java[contains(text(), 'new PhLocated(ret, 3, 2, "Φ.foo.φ")')]
- //java[contains(text(), 'new PhLocated(ret_base, 6, 4, "Φ.foo.other.φ.ρ")')]
- //java[contains(text(), 'new PhLocated(ret, 6, 6, "Φ.foo.other.φ")')]
- //java[contains(text(), 'new PhLocated(ret_1, 6, 12, "Φ.foo.other.φ.α0")')]
- //java[contains(text(), 'new PhLocated(ret_base, 10, 2, "Φ.bar.φ.ρ")')]
- //java[contains(text(), 'new PhLocated(ret, 10, 4, "Φ.bar.φ")')]
- //java[contains(text(), 'new PhLocated(ret_1, 10, 10, "Φ.bar.φ.α0")')]
- //java[contains(text(), 'new PhLocated(ret, 11, 2, "Φ.bar.five")')]
- //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")')]
input: |
# No comments.
[] > foo
Expand Down
25 changes: 19 additions & 6 deletions eo-runtime/src/main/java/org/eolang/PhLocated.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public final class PhLocated implements Phi, Atom {
*/
private final Phi origin;

/**
* EO program name (the name of the {@code .eo} file).
*/
private final String program;

/**
* The line number.
*/
Expand All @@ -61,24 +66,29 @@ public final class PhLocated implements Phi, Atom {
* Ctor.
*
* @param phi The object
* @param prg Name of the program
* @param lne Line
* @param pos Position
* @checkstyle ParameterNumberCheck (5 lines)
*/
public PhLocated(final Phi phi, final int lne, final int pos) {
this(phi, lne, pos, "?");
public PhLocated(final Phi phi, final String prg, final int lne, final int pos) {
this(phi, prg, lne, pos, "?");
}

/**
* Ctor.
*
* @param phi The object
* @param prg Name of the program
* @param lne Line
* @param pos Position
* @param loc Location
* @checkstyle ParameterNumberCheck (5 lines)
*/
public PhLocated(final Phi phi, final int lne, final int pos, final String loc) {
public PhLocated(final Phi phi, final String prg, final int lne,
final int pos, final String loc) {
this.origin = phi;
this.program = prg;
this.line = lne;
this.position = pos;
this.location = loc;
Expand Down Expand Up @@ -110,7 +120,10 @@ public String toString() {

@Override
public Phi copy() {
return new PhLocated(this.origin.copy(), this.line, this.position, this.location);
return new PhLocated(
this.origin.copy(), this.program,
this.line, this.position, this.location
);
}

@Override
Expand Down Expand Up @@ -211,8 +224,8 @@ private RuntimeException wrap(final RuntimeException cause,
*/
private String label(final String suffix) {
return String.format(
"Error in the \"%s%s\" attribute at %s:%s",
this.location, suffix, this.line, this.position
"Error in \"%s%s\" at %s:%d:%d",
this.location, suffix, this.program, this.line, this.position
);
}
}
2 changes: 1 addition & 1 deletion eo-runtime/src/test/java/org/eolang/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void executesJvmFullRunWithError() {
"Fails with the proper error message",
MainTest.exec("--verbose", "org.eolang.io.stdout"),
Matchers.containsString(
"Error in the \"Φ.org.eolang.io.stdout.φ.Δ\" attribute"
"Error in \"Φ.org.eolang.io.stdout.φ.Δ\" "
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions eo-runtime/src/test/java/org/eolang/PhLocatedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class PhLocatedTest {

@Test
void savesLocationAfterCopying() {
final Phi located = new PhLocated(new Data.ToPhi(0L), 123, 124, "qwerty");
final Phi located = new PhLocated(new Data.ToPhi(0L), "foo", 123, 124, "qwerty");
MatcherAssert.assertThat(
"saves location",
located.copy().locator(),
Expand All @@ -58,12 +58,12 @@ public byte[] delta() {
throw new IllegalArgumentException("oops");
}
},
10, 20
"foobar", 10, 20
).delta(),
"throws correct class"
),
Matchers.hasToString(
Matchers.containsString("Error in the \"?.Δ\" attribute at 10:20")
Matchers.containsString("Error in \"?.Δ\" at foobar:10:20")
)
);
}
Expand Down
1 change: 1 addition & 0 deletions eo-runtime/src/test/java/org/eolang/PhiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ void getsLocation() {
AtCompositeTest.TO_ADD_MESSAGE,
new PhLocated(
Phi.Φ,
"foobar",
123,
56,
"Φ.org.eolang$obj"
Expand Down

0 comments on commit 13e7eeb

Please sign in to comment.