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

Add non overlapping ranged annotations #7

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

meyermarcel
Copy link
Owner

No description provided.

annot_test.go Outdated
if (err != nil) != tt.wantErr {
t.Errorf("Write() error = %v, wantErr %v", err, tt.wantErr)
if tt.wantErr != nil {
if tt.wantErr.Error() != err.Error() {

Choose a reason for hiding this comment

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

I would have used

Suggested change
if tt.wantErr.Error() != err.Error() {
if !errors.Is(err, wantErr) {

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for your comment. I tried it first with errors.Is() and it didn't work. Now I figured out that I need to implement an Is() method for the custom errors.

Choose a reason for hiding this comment

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

I don't think you have, but also should, do that.

The right way is to add a Unwrap method to your custom error

Look at least the implementation

https://cs.opensource.google/go/go/+/refs/tags/go1.22.4:src/errors/wrap.go;l=44

So you should add an Unwrap and use errors.Is here

Copy link
Owner Author

Choose a reason for hiding this comment

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

What error should be unwrapped if there is no inner error?

errors.Is() is used in the latest change. Maybe it is not the right way to implement Is() method. But how does it work instead?

Choose a reason for hiding this comment

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

you return nil then

annot.go Outdated
b.WriteString(strings.Repeat(" ", a.Col-widthWritten))
if a.Col == a.pipeColIdx {
b.WriteString("├")
} else {

Choose a reason for hiding this comment

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

This multiple if-else branching is complicated and it's uneasy to see what it does

Could you move some of them on simpler functions maybe?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm also fan of early returns and less else. In this case I removed the parent if else with a continue statement.

For this particular statement I don't see any simplification. It would pack the logic in a box with self written note on it (function name). I try to avoid logic indirection behind custom names.

Choose a reason for hiding this comment

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

OK, everyone has his coding preferences 😅😂🤣

Copy link
Owner Author

@meyermarcel meyermarcel Jun 27, 2024

Choose a reason for hiding this comment

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

Thanks for your input. Putting something in a box and label it, does not always help readability. Indirection and an imaged name by the author can complicate things. In this case better an ugly else as a own made up name. An example would help to understand what you mean and what could be improved.

@meyermarcel meyermarcel force-pushed the allow-non-overlapping-ranged-annotations branch from 8f291e5 to f8dcda1 Compare June 26, 2024 21:20
@meyermarcel meyermarcel force-pushed the allow-non-overlapping-ranged-annotations branch from f8dcda1 to 2899cad Compare June 27, 2024 09:27
@meyermarcel meyermarcel merged commit b635d30 into main Jun 27, 2024
1 check passed
@meyermarcel meyermarcel deleted the allow-non-overlapping-ranged-annotations branch June 27, 2024 12:50
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.

None yet

2 participants