elm-open-api-cli icon indicating copy to clipboard operation
elm-open-api-cli copied to clipboard

When "OneOf" types get too long, they cause a corruption error in the Elm compiler cache

Open lucamug opened this issue 4 months ago • 0 comments
trafficstars

We had a case where we have several errors types that get concatendated with "or" as part of OneOf case.

The compilation from scratch of the generated Elm code works fine, but a re-compilation generated this error:

Image

It seems that the Elm compiler is not able to read back the cached files when type names are too long.

The solution that we adopted is to shorten these names with an hash.

Before:

type_ =
    Common.OneOf
        (names
            |> List.map fixOneOfName
            |> String.join "_or_"
        )
        sortedVariants

After:

type_ =
    Common.OneOf
        (names
            |> List.map fixOneOfName
            |> String.join "_or_"
            |> (\s -> "OneOf" ++ String.fromInt (Murmur3.hashString 1234 s))
        )
        sortedVariants

I will send a PR as example, but there are probably more elegant solutions

lucamug avatar Jul 07 '25 05:07 lucamug