Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2772: PhContainingUTF8 to print strings correctly #2776

Closed

Conversation

levBagryansky
Copy link
Member

@levBagryansky levBagryansky commented Jan 14, 2024

Closes #2772

Such eo code like

[] > my-error
  error > @
    "qwerty"

failed with unclear message since PhDefault::toString() implementation. So PhContainingUTF8 was introduced.


PR-Codex overview

This PR focuses on adding unit tests for the EOerror class and improving the error message handling.

Detailed summary

  • Added unit tests for EOerror class.
  • Imported necessary dependencies for unit tests.
  • Implemented getsReadableError test method.
  • Added getTestSources method to provide input arguments for the test.
  • Added MyError class to create a custom error object for testing.
  • Improved error message handling in the ExError class.
  • Added safeMessage method to safely retrieve the message from the enclosure.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@levBagryansky
Copy link
Member Author

@maxonfjvipon please take a look

Copy link
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levBagryansky good one, just several comments from my side

eo-runtime/src/test/java/EOorg/EOeolang/EOerrorTest.java Outdated Show resolved Hide resolved
@@ -55,4 +63,64 @@ void makesToxicObject() {
);
}

@Test
void getsReadableError() {
ExAbstract error = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levBagryansky can we make this variable final?
For example set it to null in try block and set to exc in catch block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon We cannot do it here, I get the error Variable 'error' might already have been assigned to: 73

@maxonfjvipon
Copy link
Member

@levBagryansky one more question: do we have a case where object inside ExError can't be dataized at all?

@levBagryansky
Copy link
Member Author

@maxonfjvipon this is a good question..

@levBagryansky
Copy link
Member Author

@maxonfjvipon please check

Copy link
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levBagryansky LGTM! Thanks

@levBagryansky
Copy link
Member Author

@yegor256 please take a look

result = "null Phi";
} else {
try {
result = new PhContainingUTF8(enclosure).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levBagryansky if this class is an instance of Phi and it makes phi objects safer by properly printing their toString(), why do we use only here, in this private method? Why don't we decorate all our phi objects with this decorator?

Copy link
Member Author

@levBagryansky levBagryansky Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yegor256 This class is correctly to use in order to print bytes of data as UTF8 String. For example, PhContainingUTF8(EOint) produces something strange. We can also use this class in Data.ToPhi(java.util.String)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@levBagryansky maybe we shouldn't call this class Phi... and should not make it a decorator of Phi? It doesn't look like a decorator to me, but a "smart" class: https://www.yegor256.com/2016/04/26/why-inputstream-design-is-wrong.html It just takes an existing instance of Phi, calls its method and then post-process the returned data. It doesn't become phi, it only is a client of Phi.

@levBagryansky
Copy link
Member Author

levBagryansky commented Jan 15, 2024

@yegor256 @maxonfjvipon , PhDefault::toString has the following implementation:

    @Override
    public String toString() {
        String result = String.format(
            "%sν%d",
            this.getClass().getCanonicalName(),
            this.vertex
        );
        if (this.attrs.containsKey("Δ")) {
            result = String.format(
                "%s=%s",
                result,
                this.attrs.get("Δ").toString()
            );
        }
        return result;
    }

So EOstring::toString does not print its content because EOstring has φ attribute with EObytes inside, not Δ. But we need to print Phi objets correctly somehow for readable exceptions. Ideally, making it correctly in cases of EOint, EOstrings. EOfloat and so on.
May be we will create such decorators and wrap to them in to-java.xsl?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unreadable exception Ex EOorg.EOeolang.EOstringν62
3 participants