GettEngineering / Prism

Gett's Design System code generator. Use Zeplin Styleguides as your R&D's Single Source of Truth.
https://prism.tools
MIT License
361 stars 21 forks source link

Failed decoding Array<TextStyle> #22

Closed gdelmas closed 4 years ago

gdelmas commented 4 years ago

I'm getting the following output. Do you have any advice for me?

 prism generate
❌ Error: Failed decoding Array<TextStyle>
freak4pc commented 4 years ago

Hey @gdelmas, Thanks for reporting and sorry for the issue!

I imagine there is something special about your Text Styles that I'm not accounting for in my decoder.

Are you able to run the tool from source (basically swift run prism generate) if I give you some instructions to add debug info ?

freak4pc commented 4 years ago

I added more detailed messaging on master. Please try:

  1. Clone the repo
  2. In your project folder, run swift run --package-path /path/to/clone prism generate

Let me know what you see :)

Thanks!

gdelmas commented 4 years ago

hey @freak4pc,

thanks for the quick response. i had already tried to run from "source".

i now get: ❌ Error: Failed decoding Array<TextStyle>: The data couldn’t be read because it is missing.

gdelmas commented 4 years ago

which api call are you doing, i might have a look into that, if it helps. and if necessary i can also start up Xcode ;)

freak4pc commented 4 years ago

It's one of the text_styles APIs but there are many of them.

Can you try running again on the last commit? Should have more verbose log message.

gdelmas commented 4 years ago

hey @freak4pc,

thanks for your commits.

i ran again and got:

❌ Error: Failed decoding Array<TextStyle>: keyNotFound(CodingKeys(stringValue: "color", intValue: nil), Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: \"color\", intValue: nil) (\"color\").", underlyingError: nil))

from debugging a little i can see this if a call to:

https://api.zeplin.dev/v1/styleguides/xxxxxxxxxxxxxxxx/text_styles?offset=0&limit=100

The response from that api do not contain any color:

  {
    "id": "5e21f2079a510456aeda1509",
    "created": 1579282951,
    "name": "ff-header / Mobile",
    "postscript_name": "SansWeb-Bold",
    "font_family": "SansWeb",
    "font_size": 18,
    "font_weight": 700,
    "font_style": "normal",
    "font_stretch": 1,
    "line_height": 19,
    "letter_spacing": 0
  },

so i conclude public let color: RawColor should be optional

freak4pc commented 4 years ago

I see the issue.

I'm not sure we want to support a case of Text Style with no color because that just makes everything much more complicated for the majority of users of Prism. (Most people have Text Styles that include a specific color).

Can you explain your specific use case so I can understand if it's something critical worth pursuing?

Regardless, we should add better error messaging around this.

gdelmas commented 4 years ago

I'm no Zeplin expert and have no idea how or why there is no colors in our Text Styles. I see the API specifies it as optional. They are part of the companies design system. We usually set the color independent of the text, as there is quite a few colors. I would have to find out why they are not included, but I guess there would be too many permutations, within multiple parent-child styleguides.

I was hoping to use Prism to translate the Zeplin stylesheets into code.

As I haven't been able to try and use Prism yet: Why would it make it more complicated for the users? I would have expected to just not use the color token or wrap it in a IF conditional. Is the problem that this IF would be required? If so, would it work to make it not required and print an error if a non present token is used?

freak4pc commented 4 years ago

I guess that's a valid point, let me look into it and I'll give you an answer later today. Thanks! :)

freak4pc commented 4 years ago

I've developed this addition over at #25, let me know if you can try it out :)