conjure icon indicating copy to clipboard operation
conjure copied to clipboard

CLI: improve error output when identifier is not valid

Open nmiyake opened this issue 6 years ago • 2 comments

The CLI properly generates an IR for the following input YAML:

types:
  definitions:
    default-package: api
    objects:
      Example:
        fields:
          data: string

However, when the object type name is changed to ExampleA:

types:
  definitions:
    default-package: api
    objects:
      ExampleA:
        fields:
          data: string

The CLI fails with the following output:

➜  bin ./conjure compile in.conjure.yml out.json
Exception in thread "main" java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct Map key of type com.palantir.conjure.parser.types.names.TypeName from String ("ExampleA"): not a valid representation: null
 at [Source: in.conjure.yml; line: 5, column: 7] (through reference chain: com.palantir.conjure.parser.Json["types"]->com.palantir.conjure.parser.types.Json["definitions"]->com.palantir.conjure.parser.types.Json["objects"])

The output message in the exception is "Can not construct Map key of type com.palantir.conjure.parser.types.names.TypeName from String ("ExampleA"): not a valid representation: null" -- this does not make it clear at all why this name failed.

The failure should be more along the lines of "ExampleA" is not a valid type name: type names be PascalCase and cannot contain 1-letter words or "ExampleA" is not a valid type name: type names must match regular expression ...

nmiyake avatar Aug 18 '18 05:08 nmiyake

This is also an issue for field names:

java.lang.RuntimeException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize Map key of type `com.palantir.conjure.parser.types.names.FieldName` from String "Name": not a valid representation, problem: (java.lang.reflect.InvocationTargetException) null
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: com.palantir.conjure.parser.ImmutableConjureSourceFile$Json["types"]->com.palantir.conjure.parser.types.ImmutableTypesDefinition$Json["definitions"]->com.palantir.conjure.parser.types.ImmutableNamedTypesDefinition$Json["objects"]->java.util.LinkedHashMap["Feature"]->com.palantir.conjure.parser.types.complex.ImmutableObjectTypeDefinition$Json["fields"])

The error should instead clearly indicate that field names cannot start with an uppercase letter.

bluekeyes avatar Feb 19 '19 23:02 bluekeyes

Got bit by this again today

gregakinman avatar Sep 29 '20 22:09 gregakinman