Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more details to fromJson error #7091

Open
Chriscbr opened this issue Sep 9, 2024 · 0 comments
Open

Add more details to fromJson error #7091

Chriscbr opened this issue Sep 9, 2024 · 0 comments
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 🎨 sdk SDK

Comments

@Chriscbr
Copy link
Contributor

Chriscbr commented Sep 9, 2024

I tried this:

bring http;
bring cloud;

struct Pokemon {
  id: str;
  name: str;
  order: num;
  weight: num;
}

new cloud.Function(inflight () => {
  let x = http.get("https://pokeapi.co/api/v2/pokemon/ditto");

  // response status
  log(x.status);

  let data = Json.parse(x.body);

  // Cast response back into struct
  let ditto = Pokemon.fromJson(data);
  log(ditto.name);

});

https://www.winglang.io/play/?code=YgByAGkAbgBnACAAaAB0AHQAcAA7AAoAYgByAGkAbgBnACAAYwBsAG8AdQBkADsACgAKAHMAdAByAHUAYwB0ACAAUABvAGsAZQBtAG8AbgAgAHsACgAgACAAaQBkADoAIABzAHQAcgA7AAoAIAAgAG4AYQBtAGUAOgAgAHMAdAByADsACgAgACAAbwByAGQAZQByADoAIABuAHUAbQA7AAoAIAAgAHcAZQBpAGcAaAB0ADoAIABuAHUAbQA7AAoAfQAKAAoAbgBlAHcAIABjAGwAbwB1AGQALgBGAHUAbgBjAHQAaQBvAG4AKABpAG4AZgBsAGkAZwBoAHQAIAAoACkAIAA9AD4AIAB7AAoAIAAgAGwAZQB0ACAAeAAgAD0AIABoAHQAdABwAC4AZwBlAHQAKAAiAGgAdAB0AHAAcwA6AC8ALwBwAG8AawBlAGEAcABpAC4AYwBvAC8AYQBwAGkALwB2ADIALwBwAG8AawBlAG0AbwBuAC8AZABpAHQAdABvACIAKQA7AAoACgAgACAALwAvACAAcgBlAHMAcABvAG4AcwBlACAAcwB0AGEAdAB1AHMACgAgACAAbABvAGcAKAB4AC4AcwB0AGEAdAB1AHMAKQA7AAoACgAgACAAbABlAHQAIABkAGEAdABhACAAPQAgAEoAcwBvAG4ALgBwAGEAcgBzAGUAKAB4AC4AYgBvAGQAeQApADsACgAKACAAIAAvAC8AIABDAGEAcwB0ACAAcgBlAHMAcABvAG4AcwBlACAAYgBhAGMAawAgAGkAbgB0AG8AIABzAHQAcgB1AGMAdAAKACAAIABsAGUAdAAgAGQAaQB0AHQAbwAgAD0AIABQAG8AawBlAG0AbwBuAC4AZgByAG8AbQBKAHMAbwBuACgAZABhAHQAYQApADsACgAgACAAbABvAGcAKABkAGkAdAB0AG8ALgBuAGEAbQBlACkAOwAKAAoAfQApADsACgAKAAoA

This happened:

I got an error: "unable to parse Pokemon:\n- Pokemon/id must be string"

I expected this:

It would have been nice to get a more clear error like "Found Pokemon.id was a number, but expected it to be a string"

Is there a workaround?

No response

Anything else?

No response

Wing Version

0.84.4

Node.js Version

20.12.2

Platform(s)

MacOS

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
@Chriscbr Chriscbr added 🐛 bug Something isn't working 🎨 sdk SDK labels Sep 9, 2024
@monadabot monadabot added this to Wing Sep 9, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New - not properly defined in Wing Sep 9, 2024
@Chriscbr Chriscbr changed the title JSON parsing error does not explain the value Add more details to fromJson error Sep 9, 2024
@Chriscbr Chriscbr added ✨ enhancement New feature or request 🛠️ compiler Compiler and removed 🐛 bug Something isn't working labels Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ compiler Compiler ✨ enhancement New feature or request 🎨 sdk SDK
Projects
Status: 🆕 New - not properly defined
Development

No branches or pull requests

1 participant