]> Repositorios git - scryer-prolog.git/commitdiff
directory_files/2: throw representation error if into_string() fails
authorMarkus Triska <[email protected]>
Sat, 20 Jun 2020 08:12:14 +0000 (10:12 +0200)
committerMarkus Triska <[email protected]>
Wed, 24 Jun 2020 21:30:40 +0000 (23:30 +0200)
Suggested by @notoria in #606. Many thanks!

src/machine/machine_errors.rs
src/machine/system_calls.rs

index 8db4c7cd247790b1b01ff9a09a91d36742d0a214..dddc58ac5697c3664fe2dbf8480f0e286bc6de5e 100644 (file)
@@ -575,7 +575,7 @@ impl DomainErrorType {
 // from 7.12.2 f) of 13211-1:1995
 #[derive(Debug, Clone, Copy)]
 pub enum RepFlag {
-    //    Character,
+    Character,
     CharacterCode,
     InCharacterCode,
     MaxArity,
@@ -586,7 +586,7 @@ pub enum RepFlag {
 impl RepFlag {
     pub fn as_str(self) -> &'static str {
         match self {
-            //            RepFlag::Character => "character",
+            RepFlag::Character => "character",
             RepFlag::CharacterCode => "character_code",
             RepFlag::InCharacterCode => "in_character_code",
             RepFlag::MaxArity => "max_arity",
index 8e25941eff187eced903ab3e4e646efa00933d73..6027f570bc146c355cd01dcf870a75e6117ecd2a 100644 (file)
@@ -830,8 +830,16 @@ impl MachineState {
                 if let Ok(entries) = fs::read_dir(path) {
                     for entry in entries {
                         if let Ok(entry) = entry {
-                            let name = entry.file_name().into_string().unwrap();
-                            files.push(self.heap.put_complete_string(&name));
+                            match entry.file_name().into_string() {
+                                Ok(name) => { files.push(self.heap.put_complete_string(&name)); }
+                                _ => {
+                                    let stub = MachineError::functor_stub(clause_name!("directory_files"), 2);
+                                    let err = MachineError::representation_error(RepFlag::Character);
+                                    let err = self.error_form(err, stub);
+
+                                    return Err(err);
+                                }
+                            }
                         }
                     }
                 }