From 87ca81c18a254a1855b65fe9821dfeef46a80829 Mon Sep 17 00:00:00 2001 From: Alie Date: Fri, 14 Jul 2023 11:03:28 +0200 Subject: [PATCH] made all errors verbose --- run_with_log.sh | 10 ++++++++++ src/main.rs | 12 ++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) create mode 100755 run_with_log.sh diff --git a/run_with_log.sh b/run_with_log.sh new file mode 100755 index 0000000..413220c --- /dev/null +++ b/run_with_log.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +mastodon-image-uploader-bot >./tmp/log.out 2>./tmp/log.err +if [ ! -s ./tmp/log.err ]; then + echo -n "$(date +"[%Y-%M-%d %T]") success: " >> ./bot.log + cat ./tmp/log.out >> ./bot.log +else + echo -n "$(date +"[%Y-%M-%d %T]") errors: " >> ./bot.log + cat ./tmp/log.err >> ./bot.log +fi \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 0dddc20..bc1908c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,8 +78,8 @@ fn get_next_url(config: &Config) -> Option { .write(true) .append(true) // This is needed to append to file .open(&config.files.posted) - .unwrap(); - write!(file, "{}\n", urls[0]).unwrap(); + .expect("Cannot open posted file"); // Maybe we should retry just in case + write!(file, "{}\n", urls[0]).expect("Cannot write to posted file"); // maybe we should retry tbh Some(urls[0].to_string().clone()) } } @@ -101,8 +101,8 @@ async fn post_image(account: &Mastodon, url: &String, config: &Config) { .visibility(Visibility::Unlisted) .sensitive(true) .build() - .unwrap(); - account.new_status(status).await.expect("Error generating status"); + .expect("Could not build status"); // we should retry + account.new_status(status).await.expect("Error generating status"); // we should retry or delete last url in posted println!("Status posted") } @@ -127,9 +127,9 @@ async fn update_bio(account: &Mastodon, config: &Config) { ), ]) .spawn() - .unwrap() + .expect("Could not spawn curl") .wait() - .unwrap(); + .expect("Curl failed"); } async fn post(account: &Mastodon, msg: &str) {