diff --git a/slinky/src/error.rs b/slinky/src/error.rs index 24e6872..5262361 100644 --- a/slinky/src/error.rs +++ b/slinky/src/error.rs @@ -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>, + }, } diff --git a/slinky/src/linker_writer.rs b/slinky/src/linker_writer.rs index 225c66a..de91559 100644 --- a/slinky/src/linker_writer.rs +++ b/slinky/src/linker_writer.rs @@ -1,6 +1,7 @@ /* SPDX-FileCopyrightText: © 2024 decompals */ /* SPDX-License-Identifier: MIT */ +use std::borrow::Cow; use std::io::Write; use crate::{ @@ -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);