Skip to content

[stdlib] Add Error.as_string_slice() and polish #4304

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martinvuyk
Copy link
Contributor

Add Error.as_string_slice() and polish

@martinvuyk martinvuyk requested a review from a team as a code owner April 6, 2025 19:25
@martinvuyk martinvuyk marked this pull request as draft April 6, 2025 19:29
@martinvuyk martinvuyk marked this pull request as ready for review April 6, 2025 20:05
),
")",
)
return String("Error(", repr(self.as_string_slice()), ")")
Copy link
Contributor

@soraros soraros Apr 6, 2025

Choose a reason for hiding this comment

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

Is the repr necessary (can we make it "Error('" etc.)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't like building a String unnecessarily, but I don't know whether to remove this. It adds " to the end and beginning of the message or ' if the message contains ", it also encodes control characters in the ASCII range. Since it encodes those characters instead of printing, I think it's worth it in cases where you would want to print something that might have been corrupted on the way. But I'm not sure.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. Maybe we should make repr return a different Writable than String in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe once we have some API for streaming a repr i.e. __repr__(self, mut writer: Writer)

Signed-off-by: martinvuyk <[email protected]>
Signed-off-by: martinvuyk <[email protected]>
@martinvuyk martinvuyk force-pushed the add-error-as-stringslice branch from 92a9cad to b97aded Compare April 15, 2025 15:40
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.

2 participants