use anyhow all over
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Cadey Ratio 2020-04-10 07:18:51 -04:00
parent b4d3cfe960
commit 722a99c8d9
4 changed files with 20 additions and 17 deletions

View File

@ -1,7 +1,8 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::{
fs::File,
io::{Read, Result, Write},
io::{Read, Write},
};
use xdg::*;
@ -14,16 +15,12 @@ pub(crate) struct Config {
pub(crate) fn load() -> Result<Config> {
let xdg_dirs =
BaseDirectories::with_prefix("cabytcini").expect("pu djica lo nu finti lei datnyveiste");
let config_path = xdg_dirs
.place_config_file("gaftercu'a.toml")
.expect("pu djica lo nu le datnyveiste be lo gaftercu'a zvati");
let config_path = xdg_dirs.place_config_file("gaftercu'a.toml")?;
match File::open(&config_path) {
Ok(mut fin) => {
let mut datni = String::new();
fin.read_to_string(&mut datni)
.expect("pu djica lo nu tcidu le sfaile");
let cfg: Config =
toml::from_str(datni.as_str()).expect("pu djica lo nu jimpe lo sfaile");
fin.read_to_string(&mut datni)?;
let cfg: Config = toml::from_str(datni.as_str())?;
Ok(cfg)
}

View File

@ -119,7 +119,7 @@ impl State {
pub(crate) fn show(&self) {
let now = Local::now().format("%H:%M M%m %-d %a");
let xsr = XSetRoot::init();
let xsr = XSetRoot::init().expect("xsetroot to initialize");
let mut msg = String::new();
@ -147,6 +147,8 @@ impl State {
msg.push_str(format!("{}", now).as_str());
xsr.render(msg);
if let Err(why) = xsr.render(msg) {
error!("error setting root window title: {:?}", why);
}
}
}

View File

@ -1,4 +1,5 @@
use crate::{config::Config, MTState};
use anyhow::Result;
use reqwest::blocking::*;
use serde::{Deserialize, Serialize};
use std::{thread, time};
@ -40,7 +41,7 @@ pub struct Daum {
const UPDATE_FREQUENCY: u64 = 15 * 60; // 15 minutes
fn get(cfg: &Config) -> reqwest::Result<Root> {
fn get(cfg: &Config) -> Result<Root> {
let client = Client::builder().user_agent(crate::APP_USER_AGENT).build()?;
let now: Root = client.get(&cfg.weather_url).send()?.json()?;

View File

@ -1,5 +1,6 @@
#![allow(unsafe_code)]
use anyhow::{anyhow, Result};
use std::ffi::CString;
use std::os::raw::c_char;
use std::ptr;
@ -11,26 +12,26 @@ pub(crate) struct XSetRoot {
}
impl XSetRoot {
pub(crate) fn init() -> Self {
pub(crate) fn init() -> Result<Self> {
unsafe {
let display = xlib::XOpenDisplay(ptr::null());
if display.is_null() {
panic!("cannot open display");
return Err(anyhow!("cannot open display"));
}
let screen = xlib::XDefaultScreen(display);
let root_window = xlib::XRootWindow(display, screen);
Self {
Ok(Self {
display,
root_window,
}
})
}
}
pub(crate) fn render(&self, text: String) {
let status_c = CString::new(text).expect("status text could not be converted to CString");
pub(crate) fn render(&self, text: String) -> Result<()> {
let status_c = CString::new(text)?;
unsafe {
xlib::XStoreName(
@ -41,6 +42,8 @@ impl XSetRoot {
xlib::XFlush(self.display);
}
Ok(())
}
}