Skip to content

Improve error reporting when a union is discriminated by a Literal type field #48

Description

@NiklasRosenstein

Example error message:

databind.core.converter.ConversionError: unable to deserialize any union member

Trace:
    $: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace)
    .workflow: TypeHint(typing.Union[helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.ApiDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.CliDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.VcsDrivenWorkflow])

The following errors have been reported by converters:

  databind.json.converters.SchemaConverter(): encountered extra keys: {'providersFrom'}

    Trace:
        $: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace)
        .workflow: TypeHint(typing.Union[helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.ApiDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.CliDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.VcsDrivenWorkflow])
        ^: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.ApiDrivenWorkflow)

  databind.json.converters.LiteralConverter(): literal value mismatch: got 'ApiDriven', expected 'CliDriven'

    Trace:
        $: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace)
        .workflow: TypeHint(typing.Union[helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.ApiDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.CliDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.VcsDrivenWorkflow])
        ^: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.CliDrivenWorkflow)
        .type: TypeHint(typing.Literal['CliDriven'])

  databind.json.converters.SchemaConverter(): missing required field: 'vcsProvider'

    Trace:
        $: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace)
        .workflow: TypeHint(typing.Union[helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.ApiDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.CliDrivenWorkflow, helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.VcsDrivenWorkflow])
        ^: TypeHint(helsing.scm.resources.v1alpha1.TerraformWorkspace.TerraformWorkspace.VcsDrivenWorkflow)

The value of the discriminator is set to VcsDriven, then only the matching members of the union should be tried.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions