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

Unknown type on errorName and fieldName collision #9

Open
tabboud opened this issue Dec 20, 2018 · 0 comments
Open

Unknown type on errorName and fieldName collision #9

tabboud opened this issue Dec 20, 2018 · 0 comments

Comments

@tabboud
Copy link
Contributor

tabboud commented Dec 20, 2018

When the errorName collides with the fieldName (either safe or unsafe), the fieldName ends up masking the private struct type, and ultimately will fail to compile.

$ go build ./...
    # github.com/tdabboud/testing/pkg/testservice/errors
    pkg/testservice/errors/errors.conjure.go:657:94: unknownSortOrder is not a type

The following conjure-IR will repro the issue

{
  "version": 1,
  "errors": [
    {
      "errorName": {
        "name": "UnknownSortOrder",
        "package": "com.palantir.testservice.errors"
      },
      "docs": "Sort order was unknown.\n",
      "namespace": "TestService",
      "code": "INVALID_ARGUMENT",
      "safeArgs": [
        {
          "fieldName": "unknownSortOrder",
          "type": {
            "type": "primitive",
            "primitive": "STRING"
           }
        }
      ],
      "unsafeArgs": []
    }
  ]
}

The resulting code

// shortened for brevity...

type unknownSortOrder struct {
	UnknownSortOrder string `json:"unknownSortOrder" yaml:"unknownSortOrder,omitempty"`
}

// NewUnknownSortOrder returns new instance of UnknownSortOrder error.
func NewUnknownSortOrder(unknownSortOrder string) *UnknownSortOrder {
	return &UnknownSortOrder{errorInstanceID: uuid.NewUUID(), unknownSortOrder: unknownSortOrder{UnknownSortOrder: unknownSortOrder}}
}

// UnknownSortOrder is an error type.
//
// Sort order was unknown.
type UnknownSortOrder struct {
	errorInstanceID uuid.UUID
	unknownSortOrder
}

As you can see above the fieldName is unknownSortOrder which collides with the private struct unknownSortOrder

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

1 participant