File tree Expand file tree Collapse file tree 1 file changed +33
-1
lines changed
Expand file tree Collapse file tree 1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change 1+ use std:: collections:: HashMap ;
12use std:: {
23 error:: Error ,
34 fmt:: { Display , Formatter } ,
45} ;
6+ use tucana:: shared:: value:: Kind :: { StringValue , StructValue } ;
7+ use tucana:: shared:: { Struct , Value } ;
58
69#[ derive( Debug , Default , Clone ) ]
710pub struct RuntimeError {
@@ -38,8 +41,37 @@ impl RuntimeError {
3841 pub fn simple ( name : & str , message : String ) -> Self {
3942 Self {
4043 name : name. to_string ( ) ,
41- message : message ,
44+ message,
4245 suggestion : None ,
4346 }
4447 }
48+
49+ pub fn as_value ( & self ) -> Value {
50+ let suggestion = match self . suggestion {
51+ Some ( ref s) => Value {
52+ kind : Some ( StringValue ( s. clone ( ) ) ) ,
53+ } ,
54+ None => Value { kind : None } ,
55+ } ;
56+
57+ Value {
58+ kind : Some ( StructValue ( Struct {
59+ fields : HashMap :: from ( [
60+ (
61+ String :: from ( "name" ) ,
62+ Value {
63+ kind : Some ( StringValue ( self . name . clone ( ) ) ) ,
64+ } ,
65+ ) ,
66+ (
67+ String :: from ( "message" ) ,
68+ Value {
69+ kind : Some ( StringValue ( self . message . clone ( ) ) ) ,
70+ } ,
71+ ) ,
72+ ( String :: from ( "suggestion" ) , suggestion) ,
73+ ] ) ,
74+ } ) ) ,
75+ }
76+ }
4577}
You can’t perform that action at this time.
0 commit comments