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

[feat] Better errors when deserializing capabilities #9951

Closed
jsimonrichard opened this issue Jun 3, 2024 · 0 comments · Fixed by #9952
Closed

[feat] Better errors when deserializing capabilities #9951

jsimonrichard opened this issue Jun 3, 2024 · 0 comments · Fixed by #9952

Comments

@jsimonrichard
Copy link
Contributor

Describe the problem

I missed in the docs (if it's there at all) that plugin names can't have underscores in them. I would have figured this out pretty quickly had the error message for serializing capabilities/default.json been more specific. However, all I got from the build script was

thread 'main' panicked at trellis/src-tauri/build.rs:14:6:
  failed to run tauri-build: failed to parse JSON: data did not match any variant of untagged enum CapabilityFile

Describe the solution you'd like

Normally, serde would give a more specific error, but it can't because it doesn't know which variant of the untagged enum to compare the file to. Based on serde-rs/serde#2157 (comment), this could be mitigated by using https://docs.rs/serde-untagged/latest/serde_untagged/index.html.

I spun up a quick-and-dirty implementation for only /core/tauri-utils/src/acl/capability.rs. I'll open a PR for it in a moment, but it obviously needs work. Before it's merged (if it is going in the right direction), we would need to find all similar instances present in other files.

The result is an error like this:

  thread 'main' panicked at build.rs:11:6:
  failed to run tauri-build: failed to parse JSON: identifiers can only include lowercase ASCII, hyphens which are not leading or trailing, and a single colon if using a prefix at line 16 column 23

It's not perfect; it would also be nice to wrap this error with some information about which file is throwing the error.

Also, it would be nice if the "no underscore" requirement for plugin names is stated in the docs. I think it might go nicely here: https://v2.tauri.app/develop/plugins/, but I don't have time to make another PR.

Alternatives considered

Besides writing our own deserializer without serde_untagged, I don't know of any other options.

Additional context

No response

@jsimonrichard jsimonrichard changed the title [feat] Better errors when deserializing capabilities (among other things) [feat] Better errors when deserializing capabilities Jun 3, 2024
@amrbashir amrbashir linked a pull request Jun 4, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant