Skip to content

gcerrors: Support unwrapping error types #3702

@Megakuul

Description

@Megakuul

Is your feature request related to a problem? Please describe.

Certain APIs like in my situation the docstore Action() return non-unwrappable error types like ActionListError.
This results in a lot of boilerplate code to achieve something for which go offers an idiomatic approach (errors.As/Is):

if err = coll.Actions().Create(a).Create(b).Create(c).Do(ctx); err != nil {
	if aErrs, ok := errors.AsType[docstore.ActionListError](err); ok {
		for _, aErr := range aErrs {
			if gcerrors.Code(aErr.Err) == gcerrors.AlreadyExists {
				return "", nil
			}
		}
	}
	return "", err
}

Describe the solution you'd like

Is there a specific reason for the usage of message codes here? Would it be viable to use error structs instead so that the go errors utilities can be used for comparison / unwrapping instead of the gcerrors package?

Describe alternatives you've considered

Writing helper utilities for the boilerplate code shown above.

Additional context

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