CLI: improve error output when identifier is not valid
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 ...
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.
Got bit by this again today