-
Notifications
You must be signed in to change notification settings - Fork 13
feat: better errors using metadata from generator #2368
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
20290c2
fix: some docs typos
ss2165 1ca115f
feat(core): check for breaking version mismatch in used extensions
ss2165 99ced9b
docs: add generator metadata keys to spec
ss2165 0381921
feat: include generator in package reading errors
ss2165 93db3a5
fix: breaking version check
ss2165 5762a42
fix typo
ss2165 e2ad704
feat: handle multiple generators
ss2165 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ use derive_more::{Display, Error, From}; | |
| use itertools::Itertools; | ||
| use std::io; | ||
|
|
||
| use super::{ExtensionBreakingError, WithGenerator, check_breaking_extensions}; | ||
| use crate::extension::ExtensionRegistry; | ||
| use crate::extension::resolution::ExtensionResolutionError; | ||
| use crate::hugr::ExtensionError; | ||
|
|
@@ -21,20 +22,24 @@ pub(super) fn from_json_reader( | |
| extensions: pkg_extensions, | ||
| } = serde_json::from_value::<PackageDeser>(val.clone())?; | ||
| let mut modules = modules.into_iter().map(|h| h.0).collect_vec(); | ||
|
|
||
| let pkg_extensions = ExtensionRegistry::new_with_extension_resolution( | ||
| pkg_extensions, | ||
| &extension_registry.into(), | ||
| )?; | ||
| ) | ||
| .map_err(|err| WithGenerator::new(err, &modules))?; | ||
|
|
||
| // Resolve the operations in the modules using the defined registries. | ||
| let mut combined_registry = extension_registry.clone(); | ||
| combined_registry.extend(&pkg_extensions); | ||
|
|
||
| for module in &mut modules { | ||
| super::check_breaking_extensions(&module, &combined_registry)?; | ||
| module.resolve_extension_defs(&combined_registry)?; | ||
| for module in &modules { | ||
| check_breaking_extensions(module, &combined_registry) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth having a variant of this function that takes a whole package?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the package is only generated at the end of this function so I'm not so sure |
||
| .map_err(|err| WithGenerator::new(err, &modules))?; | ||
| } | ||
| modules | ||
| .iter_mut() | ||
| .try_for_each(|module| module.resolve_extension_defs(&combined_registry)) | ||
| .map_err(|err| WithGenerator::new(err, &modules))?; | ||
|
|
||
| Ok(Package { | ||
| modules, | ||
|
|
@@ -65,9 +70,9 @@ pub enum PackageEncodingError { | |
| /// Error raised while reading from a file. | ||
| IOError(io::Error), | ||
| /// Could not resolve the extension needed to encode the hugr. | ||
| ExtensionResolution(ExtensionResolutionError), | ||
| ExtensionResolution(WithGenerator<ExtensionResolutionError>), | ||
| /// Error raised while checking for breaking extension version mismatch. | ||
| ExtensionVersion(super::ExtensionBreakingError), | ||
| ExtensionVersion(WithGenerator<ExtensionBreakingError>), | ||
| /// Could not resolve the runtime extensions for the hugr. | ||
| RuntimeExtensionResolution(ExtensionError), | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like it could be a footgun; should we error instead? (I see there is a
debug_assert!, but is there anything stopping this from happening?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to produce comma separated list instead (its not necessarily an error case, we could be linking modules from different sources together)