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

View File

@ -119,7 +119,7 @@ impl State {
pub(crate) fn show(&self) { pub(crate) fn show(&self) {
let now = Local::now().format("%H:%M M%m %-d %a"); 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(); let mut msg = String::new();
@ -147,6 +147,8 @@ impl State {
msg.push_str(format!("{}", now).as_str()); 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 crate::{config::Config, MTState};
use anyhow::Result;
use reqwest::blocking::*; use reqwest::blocking::*;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{thread, time}; use std::{thread, time};
@ -40,7 +41,7 @@ pub struct Daum {
const UPDATE_FREQUENCY: u64 = 15 * 60; // 15 minutes 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 client = Client::builder().user_agent(crate::APP_USER_AGENT).build()?;
let now: Root = client.get(&cfg.weather_url).send()?.json()?; let now: Root = client.get(&cfg.weather_url).send()?.json()?;

View File

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