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

Fix-should-panic-lint #127

Merged
merged 6 commits into from
Feb 24, 2024
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
17 changes: 8 additions & 9 deletions cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
connection: &zbus::Connection,
) -> OdiliaResult<Self> {
let children: Vec<CacheRef> =
AccessiblePrimitive::try_from(atspi_cache_item.object.clone())?
AccessiblePrimitive::from(atspi_cache_item.object.clone())

Check warning on line 234 in cache/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

cache/src/lib.rs#L234

Added line #L234 was not covered by tests
.into_accessible(connection)
.await?
.get_children()
Expand All @@ -240,9 +240,9 @@
.map(|child_object_pair| CacheRef::new(child_object_pair.into()))
.collect();
Ok(Self {
object: atspi_cache_item.object.try_into()?,
app: atspi_cache_item.app.try_into()?,
parent: CacheRef::new(atspi_cache_item.parent.try_into()?),
object: atspi_cache_item.object.into(),
app: atspi_cache_item.app.into(),
parent: CacheRef::new(atspi_cache_item.parent.into()),

Check warning on line 245 in cache/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

cache/src/lib.rs#L243-L245

Added lines #L243 - L245 were not covered by tests
index: atspi_cache_item.index,
children_num: atspi_cache_item.children,
interfaces: atspi_cache_item.ifaces,
Expand Down Expand Up @@ -376,7 +376,7 @@
object_pairs
.into_iter()
.map(|object_pair| {
cache.get(&object_pair.try_into()?).ok_or(
cache.get(&object_pair.into()).ok_or(

Check warning on line 379 in cache/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

cache/src/lib.rs#L379

Added line #L379 was not covered by tests
OdiliaError::Cache(
CacheError::NoItem,
),
Expand Down Expand Up @@ -565,8 +565,7 @@
})
// get "all" words that match; there should be only one result
.collect::<Vec<_>>()
// get the first result
.get(0)
.first()
// if there's no matching word (out of bounds)
.ok_or_else(|| OdiliaError::Generic("Out of bounds".to_string()))?
// clone the reference into a value
Expand Down Expand Up @@ -892,8 +891,8 @@
}?;
Ok(CacheItem {
object: accessible.try_into()?,
app: app.try_into()?,
parent: CacheRef::new(parent.try_into()?),
app: app.into(),
parent: CacheRef::new(parent.into()),

Check warning on line 895 in cache/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

cache/src/lib.rs#L894-L895

Added lines #L894 - L895 were not covered by tests
index,
children_num,
interfaces,
Expand Down
1 change: 0 additions & 1 deletion input/examples/generate-json.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use odilia_common::{events::ScreenReaderEvent, modes::ScreenReaderMode};
use serde_json;

fn main() {
// a blank event that does nothing
Expand Down
7 changes: 4 additions & 3 deletions input/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
unsafe_code
)]

use eyre::Context;
use nix::unistd::Uid;
use odilia_common::events::ScreenReaderEvent;
use std::{
Expand Down Expand Up @@ -97,7 +98,7 @@ pub async fn sr_event_receiver(
if Path::new(&sock_file_path).exists() {
tracing::trace!("Sockfile exists, attempting to remove it.");
match fs::remove_file(&sock_file_path).await {
Ok(_) => {
Ok(()) => {
tracing::debug!("Removed old socket file");
}
Err(e) => {
Expand All @@ -112,14 +113,14 @@ pub async fn sr_event_receiver(
}

match fs::write(&pid_file_path, id().to_string()).await {
Ok(_) => {}
Ok(()) => {}
Err(e) => {
tracing::error!("Unable to write to {}: {}", pid_file_path, e);
exit(1);
}
}

let listener = UnixListener::bind(sock_file_path).expect("Could not open socket");
let listener = UnixListener::bind(sock_file_path).context("Could not open socket")?;
tracing::debug!("Listener activated!");
loop {
tokio::select! {
Expand Down
21 changes: 14 additions & 7 deletions odilia/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,26 @@ async fn dispatch(state: &ScreenReaderState, event: Event) -> eyre::Result<()> {
#[cfg(test)]
pub mod dispatch_tests {
use crate::ScreenReaderState;
use eyre::Context;
use tokio::sync::mpsc::channel;

#[tokio::test]
async fn test_full_cache() {
let state = generate_state().await;
async fn test_full_cache() -> eyre::Result<()> {
let state = generate_state().await?;
assert_eq!(state.cache.by_id.len(), 14_738);
Ok(())
}

pub async fn generate_state() -> ScreenReaderState {
pub async fn generate_state() -> eyre::Result<ScreenReaderState> {
let (send, _recv) = channel(32);
let cache = serde_json::from_str(include_str!("wcag_cache_items.json")).unwrap();
let state = ScreenReaderState::new(send).await.unwrap();
state.cache.add_all(cache).unwrap();
state
let cache = serde_json::from_str(include_str!("wcag_cache_items.json"))
.context("unable to load cache data from json file")?;
let state = ScreenReaderState::new(send)
.await
.context("unable to realise screenreader state")?;
state.cache
.add_all(cache)
.context("unable to add cache to the system")?;
Ok(state)
}
}
5 changes: 3 additions & 2 deletions odilia/src/events/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
// if atomic state is false, then only read out the portion which has been added
// otherwise, do not continue through this function
let text_to_say =
if atomic { cache_text.to_string() } else { (&event.text).try_into()? };
if atomic { cache_text.to_string() } else { (&event.text).into() };

Check warning on line 191 in odilia/src/events/object.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/events/object.rs#L191

Added line #L191 was not covered by tests
let prioirty = live_to_priority(&live);
state.say(prioirty, text_to_say).await;
Ok(())
Expand All @@ -204,7 +204,7 @@
) -> eyre::Result<()> {
let accessible = state.new_accessible(event).await?;
let cache_item = state.get_or_create_event_object_to_cache(event).await?;
let updated_text: String = (&event.text).try_into()?;
let updated_text: String = (&event.text).into();

Check warning on line 207 in odilia/src/events/object.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/events/object.rs#L207

Added line #L207 was not covered by tests
let current_text = cache_item.text;
let (start_pos, update_length) =
(usize::try_from(event.start_pos)?, usize::try_from(event.length)?);
Expand Down Expand Up @@ -536,6 +536,7 @@
static A11Y_PARAGRAPH_STRING: &str = "The AT-SPI (Assistive Technology Service Provider Interface) enables users of Linux to use their computer without sighted assistance. It was originally developed at Sun Microsystems, before they were purchased by Oracle.";
lazy_static! {
static ref ZBUS_CONN: AccessibilityConnection =
#[allow(clippy::unwrap_used)]
block_on(AccessibilityConnection::open()).unwrap();
static ref CACHE_ARC: Arc<Cache> =
Arc::new(Cache::new(ZBUS_CONN.connection().clone()));
Expand Down
4 changes: 2 additions & 2 deletions odilia/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
let mut shutdown_rx_atspi_recv = shutdown_tx.subscribe();
let atspi_event_receiver =
events::receive(Arc::clone(&state), atspi_event_tx, &mut shutdown_rx_atspi_recv)
.map(|_| Ok::<_, eyre::Report>(()));
.map(|()| Ok::<_, eyre::Report>(()));

Check warning on line 88 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L88

Added line #L88 was not covered by tests
let mut shutdown_rx_atspi_proc_recv = shutdown_tx.subscribe();
let atspi_event_processor = events::process(
Arc::clone(&state),
&mut atspi_event_rx,
&mut shutdown_rx_atspi_proc_recv,
)
.map(|_| Ok::<_, eyre::Report>(()));
.map(|()| Ok::<_, eyre::Report>(()));

Check warning on line 95 in odilia/src/main.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/main.rs#L95

Added line #L95 was not covered by tests
let mut shutdown_rx_odilia_recv = shutdown_tx.subscribe();
let odilia_event_receiver = sr_event_receiver(sr_event_tx, &mut shutdown_rx_odilia_recv)
.map(|r| r.wrap_err("Could not process Odilia events"));
Expand Down
2 changes: 1 addition & 1 deletion odilia/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
&self,
atspi_cache_item: atspi_common::CacheItem,
) -> OdiliaResult<CacheItem> {
let prim = atspi_cache_item.object.clone().try_into()?;
let prim = atspi_cache_item.object.clone().into();

Check warning on line 91 in odilia/src/state.rs

View check run for this annotation

Codecov / codecov/patch

odilia/src/state.rs#L91

Added line #L91 was not covered by tests
if self.cache.get(&prim).is_none() {
self.cache.add(CacheItem::from_atspi_cache_item(
atspi_cache_item,
Expand Down
4 changes: 3 additions & 1 deletion tts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
unsafe_code
)]

use eyre::Context;
use ssip_client_async::{
fifo::asynchronous_tokio::Builder,
tokio::{AsyncClient, Request},
Expand Down Expand Up @@ -41,7 +42,8 @@ pub async fn create_ssip_client(
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("Error running `speech-dispatcher --spawn`; this is a fatal error.");
.context("Error running `speech-dispatcher --spawn`; this is a fatal error.")
?;
tracing::debug!(
"Attempting to connect to speech-dispatcher again!"
);
Expand Down
Loading