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

"humility hiffy" should allow the user to provide clarity on ambiguous enums #511

Open
jclulow opened this issue Oct 8, 2024 · 0 comments

Comments

@jclulow
Copy link
Contributor

jclulow commented Oct 8, 2024

The SP releases around 1.0.28/1.0.29 appear to contain two enums with the name SprotError. They're in different namespaces, obviously, but humility nonetheless must currently throw up its hands:

$ pfexec /tmp/humility hiffy -c SpRot.status
humility: attached to 0483:3754:003300324741500820383733 via ST-Link V3
humility hiffy failed: SprotError matches more than one enum: attest_data::messages::SprotError as GOFF 0x00039350 (object 21), drv_sprot_api::error::SprotError as GOFF 0x00044a4a (object 21)

$ /tmp/humility --version
humility 0.11.11

While it's true that the ultimate fix for this is likely to be more specific in the idol file in Hubris itself, that doesn't help folks trying to get by with images that have already been built and are in use. We could provide a way for the user to provide clarity when possible; e.g., an environment variable override might look like:

$ HIFFY_PHRASEBOOK='SprotError=drv_sprot_api::error::SprotError' pfexec /tmp/humility hiffy -c SpRot.status
humility: attached to 0483:3754:003300324741500820383733 via ST-Link V3
SpRot.status() => Err(<Complex error: SprotError>)

$ echo $?
0
diff --git a/humility-core/src/hubris.rs b/humility-core/src/hubris.rs
index 5664e4e2..e2ca445b 100644
--- a/humility-core/src/hubris.rs
+++ b/humility-core/src/hubris.rs
@@ -6445,6 +6445,46 @@ impl HubrisModule {
                     .dedup(v.iter().filter(|g| g.object == self.object))?;

                 if m.len() > 1 {
+                    /*
+                     * Allow the user to provide more specific type names by
+                     * passing a comma separated list of mappings like
+                     * "ShortName=long::name::ShortName" in the HIFFY_PHRASEBOOK
+                     * environment variable.
+                     */
+                    if let Ok(pb) = std::env::var("HIFFY_PHRASEBOOK") {
+                        for t in pb.split(',') {
+                            if let Some((k, v)) = t.split_once('=') {
+                                if k == name {
+                                    /*
+                                     * We have a phrase book entry for this
+                                     * name!  Check the filtered results to
+                                     * see if there is a single match:
+                                     */
+                                    let m = m.iter().find(|g| {
+                                        let ge = hubris.enums.get(g).unwrap();
+
+                                        if let Ok(Some(name)) =
+                                            hubris.namespaces.to_full_name(
+                                                ge.namespace,
+                                                &name.to_string(),
+                                            )
+                                        {
+                                            name == v
+                                        } else {
+                                            false
+                                        }
+                                    });
+
+                                    if let Some(m) = m {
+                                        return Ok(Some(
+                                            hubris.enums.get(&m).unwrap(),
+                                        ));
+                                    }
+                                }
+                            }
+                        }
+                    }
+
                     let all = m
                         .iter()
                         .map(|g| {
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

No branches or pull requests

1 participant