Skip to content

Commit

Permalink
avoid an unnecessary unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Aug 17, 2024
1 parent df0a03a commit 543bed3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions slinky/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ pub enum SlinkyError {
section: Cow<'static, str>,
segment: Cow<'static, str>,
},

#[error("Segment '{segment}' references undefined vram class '{vram_class}'")]
MissingVramClassForSegment {
segment: Cow<'static, str>,
vram_class: Cow<'static, str>,
},
}
12 changes: 10 additions & 2 deletions slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-FileCopyrightText: © 2024 decompals */
/* SPDX-License-Identifier: MIT */

use std::borrow::Cow;
use std::io::Write;

use crate::{
Expand Down Expand Up @@ -518,8 +519,15 @@ impl LinkerWriter<'_> {
let main_seg_sym_size: String = style.segment_vram_size(&segment.name);

if let Some(vram_class_name) = &segment.vram_class {
// TODO: return Err if vram class is not present instead of unwrapping
let vram_class = self.vram_classes.get_mut(vram_class_name).unwrap();
let vram_class = match self.vram_classes.get_mut(vram_class_name) {
Some(vc) => vc,
None => {
return Err(SlinkyError::MissingVramClassForSegment {
segment: Cow::from(segment.name.clone()),
vram_class: Cow::from(vram_class_name.clone()),
})
}
};

if !vram_class.emitted {
let vram_class_sym = style.vram_class_start(vram_class_name);
Expand Down

0 comments on commit 543bed3

Please sign in to comment.