@@ -49,3 +49,36 @@ pub fn generic_err(error: Box<dyn Error>) -> Value {
4949pub fn unknown_err ( error : String ) -> Value {
5050 Value :: Condition ( error)
5151}
52+ //
53+ // This module will likely be rewritten to look like everything below this line
54+ // The general idea is that for any submessage in an error that is truly 'variable', like
55+ // one that's sometimes:
56+ //
57+ // "Type mismatch: Expected an [Int]"
58+ //
59+ // And sometimes
60+ //
61+ // "Type mismatch: Expected a [Float that is greater than 12 but sometimes 5]"
62+ //
63+ // we cannot express this cleanly with just one pre-existing type, we need to create a new custom type
64+ // (or, if we wish to be a bit more flexible and basically forgo the type system, we can use a plain string).
65+ // In my case, I think really expressing either as either is fine, as long as the same error produces
66+ // the same message each time, which can be enforced with functions; ie
67+ //
68+ // pub weird_error() -> String {
69+ // "This always returns the same weird error"
70+ // }
71+ //
72+ // I don't forsee this the sort of thing for a bug to hide in, and one that requires strong type guarantees
73+ //
74+
75+ // We currently don't have any type that represents an interface type name, so we
76+ pub struct Cast < ' a > ( pub & ' a str ) ;
77+ pub fn cast ( expected : Cast , found : TypeTag ) -> Value {
78+ Value :: Condition ( format ! ( "Cannot cast {} to {}" , found, expected. 0 ) )
79+ }
80+
81+ /// For one off errors
82+ pub fn custom ( message : & str ) -> Value {
83+ Value :: Condition ( String :: from ( message) )
84+ }
0 commit comments