Skip to content

User-Facing Error for Invalid Config File Doesn't Contain Any Information #1020

@mckeimic

Description

@mckeimic

Summary

When the configuration file provided in the -config CLI parameter doesn't parse correctly as either a "new" style or "old" style config, the binary returns a nil error to the user instead of the more helpful errors from yaml.UnmarshalStrict().

(Edit: Looks like a duplicate of issue #979)

Behavior

$ oapi-codegen -config config.yaml openapi.json
error parsing configuration style as old version or new version: <nil>

To reproduce the error, use this (broken) config YAML:

package: nwsapi
generate:
  models: true
  embedded-spec: true
  client: true
compatability:
  always-prefix-enum-values: true

Version Information

% oapi-codegen -version
github.com/deepmap/oapi-codegen/cmd/oapi-codegen
v1.12.4

Explanation

The value of err where this error is returned is always nil because it has just passed the gate logic here.

Suggested Change

Return the current value of newErr, or both newErr and oldErr instead. This allows the user to get more information about why their provided config isn't valid from the YAML parser.

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