Skip to content

Commit 3f78cac

Browse files
committed
address several TODO convert unwrap to Error comments
1 parent 058c0f7 commit 3f78cac

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

crates/advent-of-code-data/src/client.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ impl Client for WebClient {
127127
fn get_input(&self, day: Day, year: Year) -> Result<String, ClientError> {
128128
tracing::trace!("get_input(day=`{day}`, year=`{year}`)",);
129129

130-
// TODO: Convert expects and unwraps into errors.
131-
132130
// Check if the input for this puzzle is cached locally before fetching
133131
// it from the Advent of Code service.
134132
if let Some(input) = self
@@ -144,7 +142,7 @@ impl Client for WebClient {
144142

145143
// Cache the puzzle input on disk before returning to avoid repeatedly
146144
// fetching input from the Advent of Code service.
147-
self.puzzle_cache.save_input(&input, day, year).unwrap();
145+
self.puzzle_cache.save_input(&input, day, year)?;
148146
Ok(input)
149147
}
150148

@@ -155,7 +153,6 @@ impl Client for WebClient {
155153
day: Day,
156154
year: Year,
157155
) -> Result<CheckResult, ClientError> {
158-
// TODO: Convert expects and unwraps into errors.
159156
tracing::trace!(
160157
"submit_answer(answer=`{:?}`, part=`{}`, day=`{}`, year=`{}`)",
161158
answer,
@@ -180,7 +177,7 @@ impl Client for WebClient {
180177

181178
// Check if there is an active time out on new submissions prior to
182179
// submitting to the advent of code service.
183-
let mut user = self.user_cache.load(&self.config.session_id).unwrap();
180+
let mut user = self.user_cache.load(&self.config.session_id)?;
184181

185182
if let Some(submit_wait_until) = user.submit_wait_until {
186183
if self.config.start_time <= submit_wait_until {
@@ -204,7 +201,7 @@ impl Client for WebClient {
204201
tracing::debug!("setting time to wait ({time_to_wait}) to be {wait_until}");
205202

206203
user.submit_wait_until = Some(wait_until);
207-
self.user_cache.save(&user).unwrap();
204+
self.user_cache.save(&user)?;
208205
}
209206

210207
// Write the response to the answers database and then save it back to
@@ -228,11 +225,8 @@ impl Client for WebClient {
228225
}
229226
};
230227

231-
// TODO: Report errors.
232228
tracing::debug!("Saving answers database to puzzle cache");
233-
self.puzzle_cache
234-
.save_answers(&answers, part, day, year)
235-
.unwrap();
229+
self.puzzle_cache.save_answers(&answers, part, day, year)?;
236230

237231
Ok(check_result)
238232
}

crates/advent-of-code-data/src/data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ impl Answers {
248248
pub fn deserialize<R: Read>(
249249
reader: &mut BufReader<R>,
250250
) -> Result<Self, AnswerDeserializationError> {
251+
// TODO: Convert unwrap/expect into Errors
251252
// TODO: Write tests.
252253
let mut answers = Answers::new();
253254

0 commit comments

Comments
 (0)