Skip to content

enhance: include permission identifier in ACL error messages - #15373

Merged
Legend-Master merged 3 commits into
tauri-apps:devfrom
MavenRain:code/identifier-error-context
May 24, 2026
Merged

enhance: include permission identifier in ACL error messages#15373
Legend-Master merged 3 commits into
tauri-apps:devfrom
MavenRain:code/identifier-error-context

Conversation

@MavenRain

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Enhancement to ACL error diagnostics.

Description

Closes #11262 (level 2 of the three-tier ask: identify the file and clarify
which identifier is invalid).

  • Adds three path-attached variants to the ACL Error enum (TomlFile,
    JsonFile, Json5File) carrying the parse error and the file path. The
    legacy Toml, Json, Json5 variants stay for non-file parse contexts.
  • Updates the parse call sites in acl/build.rs (3) and acl/capability.rs
    (3) to use the new variants via map_err, so the file path is reported in the
    error.
  • Changes ParseIdentifierError::InvalidFormat from a unit variant to
    InvalidFormat(String) carrying the offending identifier. Updates the message
    to say "invalid plugin or permission identifier '': ..." rather than
    the previous generic "identifiers can only include ...".

The composite effect on the user-facing error (the exact scenario from
#11262):

Before: 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

After: failed to parse JSON file '/path/to/permissions/default.toml': invalid plugin or permission identifier 'sqlite_proxy:allow-foo': identifiers can only include lowercase ASCII letters, digits, hyphens (not leading or trailing), and a single colon when using a prefix at line 16 column 23

Notes for review

  • The InvalidFormat variant signature change is technically a breaking API
    change. I verified there are zero in-tree pattern matches on
    ParseIdentifierError variants (grep -rn 'ParseIdentifierError::' crates/),
    so no internal callers break. External pattern matchers (if any) would need
    to update from InvalidFormat to InvalidFormat(_). The covector changeset
    is minor:enhance; happy to bump to major:breaking if you prefer.
  • Level 1 of the issue (docs covering naming rules) was addressed separately
    at docs(plugins): document plugin and permission identifier syntax rules tauri-docs#3826.
  • Level 3 (relaxing the underscore restriction) is a deeper change tied to
    serde_untagged (referenced in [feat] Better errors when deserializing capabilities #9951) and is intentionally out of scope here.

Build, test, fmt, clippy run locally on tauri-utils --features build,config-json5; all clean.

@MavenRain
MavenRain requested a review from a team as a code owner May 14, 2026 10:11
@github-actions

github-actions Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Package Changes Through 7d65ead

There are 2 changes which include tauri-utils with patch, tauri-bundler with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
tauri-utils 2.9.2 2.9.3
tauri-bundler 2.9.2 2.9.3
tauri-runtime 2.11.2 2.11.3
tauri-runtime-wry 2.11.2 2.11.3
tauri-codegen 2.6.2 2.6.3
tauri-macros 2.6.2 2.6.3
tauri-plugin 2.6.2 2.6.3
tauri-build 2.6.2 2.6.3
tauri 2.11.2 2.11.3
@tauri-apps/cli 2.11.2 2.11.3
tauri-cli 2.11.2 2.11.3

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

#[error("identifiers can only include lowercase ASCII, hyphens which are not leading or trailing, and a single colon if using a prefix")]
InvalidFormat,
#[error("invalid plugin or permission identifier '{0}': identifiers can only include lowercase ASCII letters, digits, hyphens (not leading or trailing), and a single colon when using a prefix")]
InvalidFormat(String),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately is a breaking change and has to wait for v3

@FabianLars FabianLars added the type: breaking change This issue or pull request will introduce a breaking change and requires major version bump label May 14, 2026
MavenRain added a commit to MavenRain/tauri that referenced this pull request May 15, 2026
…erialize boundary

  Per @FabianLars feedback on PR tauri-apps#15373: changing InvalidFormat from a unit
  variant to a tuple variant is a breaking change to ParseIdentifierError
  and needs to wait for v3.

  Revert the variant signature and capture the offending identifier value
  in the Identifier Deserialize impl instead, so the user-visible serde
  error message still names the bad entry without touching the public
  enum surface.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@MavenRain

Copy link
Copy Markdown
Contributor Author

Thanks @FabianLars, I agreed. I just pushed a revision that keeps ParseIdentifierError::InvalidFormat as a unit variant (no API change) and instead wraps the offending value into the error at the Identifier::Deserialize boundary. The user-visible serde error message is unchanged in shape (invalid plugin or permission identifier '': ), so the diagnostic improvement carries through every real parse path (TOML/JSON/JSON5 capability and permission files) without breaking anyone matching on the enum. Direct callers of Identifier::try_from see the unit-variant Display as previously seen.

The three new path-attached parse variants (Error::TomlFile, Error::JsonFile, and Error::Json5File) are additive and remain in this PR; let me know if you want any of those split-out as well.

@Legend-Master Legend-Master removed the type: breaking change This issue or pull request will introduce a breaking change and requires major version bump label May 18, 2026
@Legend-Master Legend-Master added this to the 2.12 milestone May 18, 2026

/// Invalid TOML encountered
#[error("failed to parse TOML: {0}")]
Toml(#[from] toml::de::Error),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's deprecate the old ones and add a todo for the removal in v3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually.. We didn't mark this error type #[non_exhaustive] so adding a new type is also breaking...

Do you mind splitting the Identifier deserialization code to a new PR so we can merge it first? The error message change will probably need to wait for v3

Comment thread crates/tauri-utils/src/acl/mod.rs Outdated

/// Invalid TOML encountered while parsing a known file.
#[error("failed to parse TOML file '{}': {}", _1.display(), _0)]
TomlFile(toml::de::Error, PathBuf),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we align this with

e.g.

    /// The path that failed to parse into JSON.
    path: PathBuf,

    /// The parsing [`serde_json::Error`].
    error: serde_json::Error,

(p.s. not the name, just tuple to struct)

@Legend-Master Legend-Master added the type: breaking change This issue or pull request will introduce a breaking change and requires major version bump label May 18, 2026
@Legend-Master Legend-Master modified the milestones: 2.12, 3.0 May 18, 2026
MavenRain added a commit to MavenRain/tauri that referenced this pull request May 21, 2026
…rialize

  wrapping

  Legend-Master noted on PR tauri-apps#15373 that `Error` is not `#[non_exhaustive]`,
  so adding `TomlFile`/`JsonFile`/`Json5File` variants is itself a breaking
  change.

  Drop those variants and revert the build/capability call sites to the
  existing `Toml`/`Json`/`Json5` variants via `#[from]`.  Keep only the
  `Identifier::Deserialize` wrapping so the offending identifier still
  appears in the serde error message.  File-path attached parse variants
  can return as struct variants in v3.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@MavenRain
MavenRain force-pushed the code/identifier-error-context branch from 79e7ab8 to 5c40858 Compare May 21, 2026 00:02

@Legend-Master Legend-Master left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, awesome improvement!

Also you'll need to sign your commits for me to merge this

https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

@Legend-Master Legend-Master changed the title feat(acl): include file path and offending identifier in error messages enhance: include permission identifier in ACL error messages May 22, 2026
@Legend-Master Legend-Master removed the type: breaking change This issue or pull request will introduce a breaking change and requires major version bump label May 22, 2026
@Legend-Master Legend-Master modified the milestones: 3.0, 2.12 May 22, 2026
MavenRain added 3 commits May 24, 2026 04:03
  Adds Error::TomlFile, Error::JsonFile, and Error::Json5File variants that
  carry the file path. ParseIdentifierError::InvalidFormat now carries the
  offending value as a String. Together these turn the previous opaque build
  failure into one that names the file and the bad identifier.

Closes tauri-apps#11262

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
…erialize boundary

  Per @FabianLars feedback on PR tauri-apps#15373: changing InvalidFormat from a unit
  variant to a tuple variant is a breaking change to ParseIdentifierError
  and needs to wait for v3.

  Revert the variant signature and capture the offending identifier value
  in the Identifier Deserialize impl instead, so the user-visible serde
  error message still names the bad entry without touching the public
  enum surface.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
…rialize

  wrapping

  Legend-Master noted on PR tauri-apps#15373 that `Error` is not `#[non_exhaustive]`,
  so adding `TomlFile`/`JsonFile`/`Json5File` variants is itself a breaking
  change.

  Drop those variants and revert the build/capability call sites to the
  existing `Toml`/`Json`/`Json5` variants via `#[from]`.  Keep only the
  `Identifier::Deserialize` wrapping so the offending identifier still
  appears in the serde error message.  File-path attached parse variants
  can return as struct variants in v3.

Signed-off-by: Onyeka Obi <softwareengineerasaservant@isurvivable.cv>
@MavenRain
MavenRain force-pushed the code/identifier-error-context branch from 5c40858 to 7d65ead Compare May 24, 2026 11:17
@Legend-Master
Legend-Master merged commit c2b8f47 into tauri-apps:dev May 24, 2026
23 checks passed
@MavenRain
MavenRain deleted the code/identifier-error-context branch May 26, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] Plugin names should be able to include underscore '_'

3 participants