Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cmd/dump/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,14 @@ fn dump_via_agent(
if !subargs.simulate_dumper {
bail!("--simulate-task-dump requires --simulate-dumper");
}
let ndx = match hubris.lookup_task(task) {
Some(HubrisTask::Task(ndx)) => ndx,
_ => {
bail!("invalid task \"{task}\"");
let ndx = match hubris.try_lookup_task(task)? {
HubrisTask::Task(ndx) => ndx,
HubrisTask::Kernel => {
bail!("cannot dump \"{task}\" because it is the kernel")
}
};

Some(DumpTask::new(*ndx as u16, hubris.ticks(core)?))
Some(DumpTask::new(ndx as u16, hubris.ticks(core)?))
}
None => None,
};
Expand Down Expand Up @@ -709,10 +709,10 @@ fn dump_task_via_agent(
let mut agent = get_dump_agent(hubris, core, subargs)?;

let task = subargs.task.as_ref().unwrap();
let ndx = match hubris.lookup_task(task) {
Some(HubrisTask::Task(ndx)) => *ndx,
_ => {
bail!("invalid task \"{task}\"");
let ndx = match hubris.try_lookup_task(task)? {
HubrisTask::Task(ndx) => ndx,
HubrisTask::Kernel => {
bail!("cannot dump \"{task}\" because it is the kernel")
}
};
if ndx == 0 {
Expand Down
8 changes: 2 additions & 6 deletions cmd/hiffy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//!

use ::idol::syntax::{Operation, Reply};
use anyhow::{Context, Result, anyhow, bail};
use anyhow::{Context, Result, bail};
use clap::{CommandFactory, Parser};
use humility::hubris::*;
use humility::warn;
Expand Down Expand Up @@ -259,11 +259,7 @@ fn hiffy(context: &mut ExecutionContext) -> Result<()> {
}

let task = match subargs.task {
Some(task) => Some(
hubris
.lookup_task(&task)
.ok_or_else(|| anyhow!("unknown task \"{}\"", task))?,
),
Some(task) => Some(hubris.try_lookup_task(&task)?),
None => None,
};

Expand Down
8 changes: 3 additions & 5 deletions cmd/jefe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
//! As with tasks held by `--hold`, use `--release`/`-r` to set the task back to
//! normal, or `--start`/`-s` to run it once but catch the next fault.

use anyhow::{Result, anyhow, bail};
use anyhow::{Result, bail};
use clap::{CommandFactory, Parser};
use humility::hubris::*;
use humility_cli::{ExecutionContext, Subcommand};
Expand Down Expand Up @@ -150,16 +150,14 @@ fn jefe(context: &mut ExecutionContext) -> Result<()> {
bail!("one of fault, start, hold, or release must be specified");
};

let task = hubris
.lookup_task(&subargs.task)
.ok_or_else(|| anyhow!("couldn't find task {}", subargs.task))?;
let task = hubris.try_lookup_task(&subargs.task)?;

let id = match task {
HubrisTask::Kernel => {
bail!("cannot change disposition of kernel");
}
HubrisTask::Task(id) => {
if let Some(id) = NonZeroU32::new(*id) {
if let Some(id) = NonZeroU32::new(id) {
id
} else {
bail!("cannot change disposition of supervisor task");
Expand Down
2 changes: 1 addition & 1 deletion cmd/powershelf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn lookup_operation_enum(hubris: &HubrisArchive) -> Result<&HubrisEnum> {
anyhow!("missing `power` task - is this a PSC archive?")
})?;

let module = hubris.lookup_module(*power_task)?;
let module = hubris.lookup_module(power_task)?;

// `Operation` matches multiple enums, and `task_power_api::Operation`
// doesn't show up alone, but `Option<task_power_api::Operation>` does! Find
Expand Down
8 changes: 2 additions & 6 deletions cmd/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl<'a> RpcClient<'a> {
)
})?;
let rpc_reply_type = hubris
.lookup_module(*rpc_task)?
.lookup_module(rpc_task)?
.lookup_enum_byname(hubris, "RpcReply")?
.ok_or_else(|| anyhow!("can't find RpcReply"))?;

Expand Down Expand Up @@ -550,11 +550,7 @@ fn rpc_run(context: &mut ExecutionContext) -> Result<()> {
}

let task = match &subargs.task {
Some(task) => Some(
hubris
.lookup_task(task)
.ok_or_else(|| anyhow!("unknown task \"{}\"", task))?,
),
Some(task) => Some(hubris.try_lookup_task(task)?),
None => None,
};

Expand Down
8 changes: 4 additions & 4 deletions humility-core/src/hubris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1976,15 +1976,15 @@ impl HubrisArchive {
self.modules.values()
}

pub fn lookup_task(&self, name: &str) -> Option<&HubrisTask> {
self.tasks.get(name)
pub fn lookup_task(&self, name: &str) -> Option<HubrisTask> {
self.tasks.get(name).copied()
}

/// Tries to look up a task by name, returning an error with similar names
pub fn try_lookup_task(&self, name: &str) -> Result<HubrisTask> {
self.tasks
.get(name)
.cloned()
.copied()
.ok_or_else(|| self.task_name_suggestion(name))
}

Expand Down Expand Up @@ -6684,7 +6684,7 @@ impl ExternRegions {

for (name, task) in &config.tasks {
if task.extern_regions.is_some() {
set.insert(*hubris.lookup_task(name).unwrap());
set.insert(hubris.lookup_task(name).unwrap());
}
}

Expand Down
4 changes: 2 additions & 2 deletions humility-hiffy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'a> HiffyContext<'a> {

Some(
hubris
.lookup_module(*rpc_task)?
.lookup_module(rpc_task)?
.lookup_enum_byname(hubris, "RpcReply")?
.ok_or_else(|| anyhow!("failed to find RpcReply"))?,
)
Expand Down Expand Up @@ -984,7 +984,7 @@ impl<'a> HiffyContext<'a> {
None
}

HubrisTask::Task(i) => Some(*i),
HubrisTask::Task(i) => Some(i),
}
});

Expand Down
6 changes: 3 additions & 3 deletions humility-idol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> IdolOperation<'a> {
hubris: &'a HubrisArchive,
interface: &str,
operation: &str,
task: Option<&HubrisTask>,
task: Option<HubrisTask>,
) -> Result<Self> {
let (task, op, code) = lookup(hubris, interface, operation, task)?;
let name = (interface.to_string(), operation.to_string());
Expand Down Expand Up @@ -309,15 +309,15 @@ fn lookup<'a>(
hubris: &'a HubrisArchive,
interface: &str,
operation: &str,
target: Option<&HubrisTask>,
target: Option<HubrisTask>,
) -> Result<(HubrisTask, &'a Operation, u16)> {
//
// Find this interface and its operation.
//
let mut rval = None;

let tasks = match target {
Some(task) => vec![*task],
Some(task) => vec![task],
None => {
(0..hubris.ntasks()).map(|t| HubrisTask::Task(t as u32)).collect()
}
Expand Down
Loading