11use std:: sync:: { Arc , RwLock } ;
22
3- use anyhow:: anyhow;
3+ use anyhow:: { anyhow, Context } ;
44use matrix_sdk:: {
55 config:: SyncSettings ,
66 media:: { MediaFormat , MediaRequest , MediaThumbnailSize } ,
@@ -129,7 +129,7 @@ impl Client {
129129
130130 pub fn restore_token ( & self ) -> anyhow:: Result < String > {
131131 RUNTIME . block_on ( async move {
132- let session = self . client . session ( ) . expect ( "Missing session" ) ;
132+ let session = self . client . session ( ) . context ( "Missing session" ) ? ;
133133 let homeurl = self . client . homeserver ( ) . await . into ( ) ;
134134 Ok ( serde_json:: to_string ( & RestoreToken {
135135 session,
@@ -141,28 +141,28 @@ impl Client {
141141 }
142142
143143 pub fn user_id ( & self ) -> anyhow:: Result < String > {
144- let user_id = self . client . user_id ( ) . expect ( "No User ID found" ) ;
144+ let user_id = self . client . user_id ( ) . context ( "No User ID found" ) ? ;
145145 Ok ( user_id. to_string ( ) )
146146 }
147147
148148 pub fn display_name ( & self ) -> anyhow:: Result < String > {
149149 let l = self . client . clone ( ) ;
150150 RUNTIME . block_on ( async move {
151- let display_name = l. account ( ) . get_display_name ( ) . await ?. expect ( "No User ID found" ) ;
151+ let display_name = l. account ( ) . get_display_name ( ) . await ?. context ( "No User ID found" ) ? ;
152152 Ok ( display_name)
153153 } )
154154 }
155155
156156 pub fn avatar_url ( & self ) -> anyhow:: Result < String > {
157157 let l = self . client . clone ( ) ;
158158 RUNTIME . block_on ( async move {
159- let avatar_url = l. account ( ) . get_avatar_url ( ) . await ?. expect ( "No User ID found" ) ;
159+ let avatar_url = l. account ( ) . get_avatar_url ( ) . await ?. context ( "No User ID found" ) ? ;
160160 Ok ( avatar_url. to_string ( ) )
161161 } )
162162 }
163163
164164 pub fn device_id ( & self ) -> anyhow:: Result < String > {
165- let device_id = self . client . device_id ( ) . expect ( "No Device ID found" ) ;
165+ let device_id = self . client . device_id ( ) . context ( "No Device ID found" ) ? ;
166166 Ok ( device_id. to_string ( ) )
167167 }
168168
@@ -235,13 +235,13 @@ impl Client {
235235 return Ok ( Arc :: new ( session_verification_controller. clone ( ) ) ) ;
236236 }
237237
238- let user_id = self . client . user_id ( ) . expect ( "Failed retrieving current user_id" ) ;
238+ let user_id = self . client . user_id ( ) . context ( "Failed retrieving current user_id" ) ? ;
239239 let user_identity = self
240240 . client
241241 . encryption ( )
242242 . get_user_identity ( user_id)
243243 . await ?
244- . expect ( "Failed retrieving user identity" ) ;
244+ . context ( "Failed retrieving user identity" ) ? ;
245245
246246 let session_verification_controller = SessionVerificationController :: new ( user_identity) ;
247247
0 commit comments