@@ -516,9 +516,9 @@ open class Module {
516
516
break
517
517
518
518
default :
519
- fatalError (
520
- " Unable to set \( path. joined ( separator : " . " ) ) on \( modulePath. joined ( separator : " . " ) ) : \( item) not compatible with \( value . mapValues { $0 . shape . description } ) "
521
- )
519
+ throw UpdateError . incompatibleItems (
520
+ path: path , modules : modulePath, item : item. description,
521
+ value : String ( describing : ( value . mapValues { $0 . shape . description } ) ) )
522
522
}
523
523
}
524
524
@@ -630,9 +630,7 @@ open class Module {
630
630
631
631
switch ( item, value) {
632
632
case ( . value( . parameters) , . value) :
633
- fatalError (
634
- " Unable to set \( path. joined ( separator: " . " ) ) on \( modulePath. joined ( separator: " . " ) ) : parameters (MLXArray) cannot be updated with a Module "
635
- )
633
+ throw UpdateError . settingArrayWithModule ( path: path, modules: modulePath)
636
634
637
635
case ( . array( let items) , . array( let values) ) :
638
636
// Could be:
@@ -689,9 +687,7 @@ open class Module {
689
687
}
690
688
}
691
689
default :
692
- fatalError (
693
- " Unexpected structure for \( key) on \( self ) : not @ModuleInfo var modules = [...] "
694
- )
690
+ throw UpdateError . unexpectedStructure ( key: key, item: self . description)
695
691
}
696
692
697
693
case ( . dictionary, . dictionary( let values) ) :
@@ -723,9 +719,9 @@ open class Module {
723
719
try module. update ( modules: NestedDictionary ( values: values) , verify: verify)
724
720
725
721
default :
726
- fatalError (
727
- " Unable to set \( path. joined ( separator : " . " ) ) on \( modulePath. joined ( separator : " . " ) ) : \( item) not compatible with \( value ) "
728
- )
722
+ throw UpdateError . incompatibleItems (
723
+ path: path , modules : modulePath, item : item. description ,
724
+ value : value . description )
729
725
}
730
726
}
731
727
@@ -1573,6 +1569,9 @@ enum UpdateError: Error {
1573
1569
case unableToSet( String )
1574
1570
case unableToCast( String )
1575
1571
case unhandledKeys( path: [ String ] , modules: [ String ] , keys: [ String ] )
1572
+ case settingArrayWithModule( path: [ String ] , modules: [ String ] )
1573
+ case incompatibleItems( path: [ String ] , modules: [ String ] , item: String , value: String )
1574
+ case unexpectedStructure( key: String , item: String )
1576
1575
}
1577
1576
1578
1577
extension UpdateError : LocalizedError {
@@ -1599,6 +1598,15 @@ extension UpdateError: LocalizedError {
1599
1598
case . unhandledKeys( let path, let modules, let keys) :
1600
1599
return
1601
1600
" Unhandled keys \( keys) in \( path. joined ( separator: " . " ) ) in \( modules. joined ( separator: " . " ) ) "
1601
+ case . settingArrayWithModule( let path, let modules) :
1602
+ return
1603
+ " Unable to set \( path. joined ( separator: " . " ) ) on \( modules. joined ( separator: " . " ) ) : parameters (MLXArray) cannot be updated with a Module "
1604
+ case . incompatibleItems( let path, let modules, let item, let value) :
1605
+ return
1606
+ " Unable to set \( path. joined ( separator: " . " ) ) on \( modules. joined ( separator: " . " ) ) : \( item) not compatible with \( value) "
1607
+ case . unexpectedStructure( let key, let item) :
1608
+ return " Unexpected structure for \( key) on \( item) : not @ModuleInfo var modules = [...] "
1609
+
1602
1610
}
1603
1611
}
1604
1612
}
0 commit comments