Skip to content

improve error reporting if outer delimiters are available#194

Merged
sunshowers merged 4 commits into
mainfrom
sunshowers/spr/improve-error-reporting-if-outer-delimiters-are-available
Jun 11, 2024
Merged

improve error reporting if outer delimiters are available#194
sunshowers merged 4 commits into
mainfrom
sunshowers/spr/improve-error-reporting-if-outer-delimiters-are-available

Conversation

@sunshowers

@sunshowers sunshowers commented Jun 11, 2024

Copy link
Copy Markdown
Contributor

Currently, if there's a top-level error in the macro (e.g. a top-level missing
field), then we always get a call_site error. That is because we don't have the
span information corresponding to the outer braces.

This isn't a huge problem if serde_tokenstream is used for the top-level
attribute, but does become one for nested attributes. Trait-based Dropshot
servers are one such case -- endpoint annotations are nested under the
top-level and can be pretty far from the call site.

Address this by providing an alternative API that also accepts delimiter spans.

Also remove the .vscode/settings.json that's no longer required,
and allow the target gitignore rule to match a symlink (all my target
directories are symlinks to a non-btrfs-snapshotted store).

Created using spr 1.3.6-beta.1
@sunshowers sunshowers requested a review from ahl June 11, 2024 00:27
Created using spr 1.3.6-beta.1

@ahl ahl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • Nice find!
  • Do we want to update the main lib.rs info and/or README? In particular to guide users who may encounter a similar situation as you did.
  • This may be somewhere in the dumb-to-optimistic range, but given the input TokenStream could we construct a Span that encompasses its entirety and use that by default?
  • ... Or was this just the wrong interface and we should have had users pass in the outer, braced tokenstream??

Comment thread .vscode/settings.json Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

let's delete this file? I probably shouldn't have added it in the first place. I bet we no longer need the nightly rustfmt?

Comment thread testlib/src/lib.rs Outdated
Comment thread src/serde_tokenstream.rs Outdated
Comment on lines +67 to +68
/// This is useful with nested attributes inside annotations, where
/// `serde_tokenstream` is used to parse an attribute inside a top-level macro.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// This is useful with nested attributes inside annotations, where
/// `serde_tokenstream` is used to parse an attribute inside a top-level macro.
/// This is useful with nested attributes inside annotations, when
/// parsing an attribute nested inside an outer macro.

maybe?

Comment thread src/serde_tokenstream.rs
///
/// ```rust,ignore
/// #[derive(Record)]
/// #[record { worker = "Homer J. Simpson", floor = 7, region = "G" }]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread src/serde_tokenstream.rs Outdated
Comment thread src/serde_tokenstream.rs Outdated
Comment thread src/serde_tokenstream.rs
Created using spr 1.3.6-beta.1
@sunshowers

sunshowers commented Jun 11, 2024

Copy link
Copy Markdown
Contributor Author
  • Nice find!

  • Do we want to update the main lib.rs info and/or README? In particular to guide users who may encounter a similar situation as you did.

Done.

  • This may be somewhere in the dumb-to-optimistic range, but given the input TokenStream could we construct a Span that encompasses its entirety and use that by default?

We could, but that would cause an inconsistency where only the part inside the braces would be included, not the braces themselves. I think the current approach is probably fine -- it complains about the whole macro.

  • ... Or was this just the wrong interface and we should have had users pass in the outer, braced tokenstream??

Ah sadly the outer TokenStream isn't available with top-level attributes.

Created using spr 1.3.6-beta.1
@sunshowers sunshowers merged commit bd0453b into main Jun 11, 2024
@sunshowers sunshowers deleted the sunshowers/spr/improve-error-reporting-if-outer-delimiters-are-available branch June 11, 2024 23:25
@ahl

ahl commented Jun 12, 2024

Copy link
Copy Markdown
Collaborator

In v0.2.1 now on crates.io

sunshowers added a commit to oxidecomputer/dropshot that referenced this pull request Jun 12, 2024
This is a bit of a basic/elementary test but I realized we didn't have coverage
for it. (And it's actually important for server traits -- specifically, without
oxidecomputer/serde_tokenstream#194,
incorrect span information is produced.)
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.

2 participants