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

If prevErr.isZero() is true, it will skip writing current error string. #640

Open
mritunjaykumar opened this issue Feb 23, 2021 · 2 comments

Comments

@mritunjaykumar
Copy link

mritunjaykumar commented Feb 23, 2021

I believe there is a bug at this line https://github.com/upspin/upspin/blob/master/errors/errors.go#L265
rather than

	if e.Err != nil {
		// Indent on new line if we are cascading non-empty Upspin errors.
		if prevErr, ok := e.Err.(*Error); ok {
			if !prevErr.isZero() {
				pad(b, Separator)
				b.WriteString(e.Err.Error())
			}
		} else {
			pad(b, ": ")
			b.WriteString(e.Err.Error())
		}
	}

it should be

	if e.Err != nil {
		// Indent on new line if we are cascading non-empty Upspin errors.
		if prevErr, ok := e.Err.(*Error); ok {
			if !prevErr.isZero() {
				pad(b, Separator)
			} else {
                                 pad(b, ": ")
                         }
		} else {
			pad(b, ": ")
		}
		b.WriteString(e.Err.Error())
	}
@adg
Copy link
Collaborator

adg commented Mar 16, 2021

I believe you are correct.

@oec
Copy link
Contributor

oec commented Feb 13, 2024

I think the original behaviour is correct, albeit confusing:

  1. changing the code to the suggested or equivalent code breaks the test TestDoesNotChangePreviousError
  2. if prevErr.isZero() is true, there is nothing to print.

I think it would be less confusing if the first call to WriteString would use prevErr.Error(), not e.Err.Error()

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

No branches or pull requests

3 participants