Navigation Menu

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

Make it easier to instantiate ProblemDetails #1837

Closed
jsha opened this issue May 23, 2016 · 1 comment
Closed

Make it easier to instantiate ProblemDetails #1837

jsha opened this issue May 23, 2016 · 1 comment
Assignees

Comments

@jsha
Copy link
Contributor

jsha commented May 23, 2016

Right now we have a common pattern:

return &probs.ProblemDetails{
  Type: probs.ConnectionProblem,
  Detail: err.Error(),
}

This is unnecessarily verbose and makes it harder to read the surrounding code. Instead, we should turn each of the probs.*Problem variables from ProblemTypes into functions, and say:

return probs.ConnectionProblem(err)
@cpu
Copy link
Contributor

cpu commented May 27, 2016

I like the idea of having probs.*Problem functions to quickly construct a ProblemDetails of the right type. It looks like some of the ProblemTypes have functions like this already (e.g. BadNonceProblem has BadNonce).

I will add one for ConnectionProblem and convert callers using the explicit ProblemDetails struct instantiation.

@cpu cpu self-assigned this May 27, 2016
@jsha jsha added this to the Sprint 2016-05-31 milestone May 31, 2016
jsha pushed a commit that referenced this issue May 31, 2016
Several of the `ProblemType`s had convenience functions to instantiate `ProblemDetails`s using their type and a detail message. Where these existed I did a quick scan of the codebase to convert places where callers were explicitly constructing the `ProblemDetails` to use the convenience function.

For the `ProblemType`s that did not have such a function, I created one and then converted callers to use it.

Solves #1837.
@cpu cpu closed this as completed Jun 3, 2016
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

2 participants