unicode-org / icu4x

Solving i18n for client-side and resource-constrained environments.
https://icu4x.unicode.org
Other
1.38k stars 176 forks source link

Figure out error story for FFI #703

Closed Manishearth closed 2 years ago

Manishearth commented 3 years ago

Right now FFI just returns bools for error cases.

We should eventually figure out how we want to expose error states over FFI and write error enums for these. The current design is easily extended to error enums.

The hard part here is mostly handling complex error states.

sffc commented 3 years ago

Discussion:

Conclusion:

sffc commented 3 years ago

Make a plan for what to do this quarter, and implement in Q1 2022.

sffc commented 2 years ago

Discussion 2022-05-27:

  1. Enums over diplomat corresponding to enums in Rust
  2. Strings built from the Display impl
  3. Strings in debug mode; bool or similar in release mode
  4. Static strings
  5. Opaque error type that has a to_string
  6. Global flat error enum

Consensus: Single common error enum, with strings optionally logged using the Rust logger.

LGTM: @QnnOkabayashi @robertbastian @nordzilla @Manishearth @sffc @zbraniecki

Manishearth commented 2 years ago

So I was getting ready to start implementing this and I realized that in Diplomat, enums become strings in JS, converted after being received as integers. For the JS backend are we okay with that or would we want to return an integer instead?

Ideally Diplomat has support for consts so we can return an integer that you can check against a constant list.

sffc commented 2 years ago

So I was getting ready to start implementing this and I realized that in Diplomat, enums become strings in JS, converted after being received as integers. For the JS backend are we okay with that or would we want to return an integer instead?

Ideally Diplomat has support for consts so we can return an integer that you can check against a constant list.

IMO, I think it's fairly standard for errors to be strings in JS, and this would be my expected behavior. The main thing is that the strings are stable, which for enums they should be.

zbraniecki commented 2 years ago

Hah, that's exactly why I'd prefer not to use strings. Because if we make strings stable we corner ourselves away from ability to improve error messages. I'm ok with string identifiers or numerical error codes plus payload.

Manishearth commented 2 years ago

yeah these would be string identifiers like "ICU4X_PLURALS_OOPSIE" (and an enum variant of the same name in C++) which we would stabilize

zbraniecki commented 2 years ago

I'm happy with ICU4X_PLURALS_OOPSIE. More, I now demand that we add it.