Skip to content

Safe and Unsafe arg names can collide with method names on an error #179

@asanderson15

Description

@asanderson15

There is bug is in the generation code, specifically the way we inline the private error type rather than naming it. Take the example of the following definition:

types:
  definitions:
    errors:
      MyError:
        code: CUSTOM_SERVER
        namespace: MyNamespace
        safe-args:
          code: integer
          message: string

The above definition would generate roughly the following:

type myError {
  Code int
  Message string
}

type MyError struct {
  errorInstanceID uuid.UUID
  myError
  cause error
  stack werror.StackTrace
}

The collision occurs on the generated SafeParams method.

// safeParams returns a set of named safe parameters detailing this particular error instance.
func (e *MyError) safeParams() map[string]interface{} {
	return map[string]interface{}{"code": e.Code, "message": e.Message, "errorInstanceId": e.errorInstanceID}
}

Because Code and Message are also methods on MyError, this actually returns functions rather than the values stored on myError.

Think the fix is just to name the internal error type on the exported error type - I don't see any reason this needs to be inlined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions