Skip to content

Commit

Permalink
Backend/Marshalling: protect against possible NRE
Browse files Browse the repository at this point in the history
Somehow I got this NRE once and couldn't reproduce it again, but let's
add some protection to it in case it happens again:

Available operations:
0: Exit
1: Refresh
3: Send payment
4: Add readonly accounts
5: Sign off payment
6: Broadcast payment
7: Archive account
8: Pair to watch wallet
9: Options
Choose operation to perform: 6
Introduce a file name to load the signed transaction: sReb.json
System.NullReferenceException: Object reference not set to an instance of an object
  at GWallet.Backend.Marshalling.ExtractType (System.String json) [0x00000] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Marshalling.fs:149
  at GWallet.Backend.Account.ImportSignedTransactionFromJson (System.String json) [0x00000] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Account.fs:609
  at GWallet.Backend.Account.LoadSignedTransactionFromFile (System.String filePath) [0x00007] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Account.fs:626
  at Program.BroadcastPayment () [0x0000b] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:43
  at Program.PerformOperation (System.Int32 numAccounts) [0x00142] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:312
  at Program.ProgramMainLoop[a] () [0x0004c] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:369
  at Program.NormalStartWithNoParameters () [0x00007] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:379
System.NullReferenceException: Object reference not set to an instance of an object
  at GWallet.Backend.Infrastructure.Report (System.Exception ex, SharpRaven.Data.ErrorLevel _arg1) [0x00019] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:131
  at GWallet.Backend.Infrastructure.LogOrReportCrash (System.Exception ex) [0x00000] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:148
  at Program.NormalStartWithNoParameters () [0x00017] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:383
  at Program.main (System.String[] argv) [0x0002b] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:401
exception inside UnhandledException handler: (null) assembly:/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/4.5/mscorlib.dll type:NullReferenceException member:(null)

[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
  at GWallet.Backend.Infrastructure.Report (System.Exception ex, SharpRaven.Data.ErrorLevel _arg1) [0x00019] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:131
  at GWallet.Backend.Infrastructure.LogOrReportCrash (System.Exception ex) [0x00000] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:148
  at Program.NormalStartWithNoParameters () [0x00017] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:383
  at Program.main (System.String[] argv) [0x0002b] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Frontend.Console/Program.fs:401
  at GWallet.Backend.Infrastructure.Report (System.Exception ex, SharpRaven.Data.ErrorLevel _arg1) [0x00019] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:131
  at GWallet.Backend.Infrastructure.LogOrReportCrash (System.Exception ex) [0x00000] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:148
  at GWallet.Backend.Infrastructure.OnUnhandledException (System.Object _arg1, System.UnhandledExceptionEventArgs args) [0x0000e] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:162
  at [email protected] (System.Object delegateArg0, System.UnhandledExceptionEventArgs delegateArg1) [0x00000] in /Users/knocte/Documents/Code/geewalletMaster/src/GWallet.Backend/Infrastructure.fs:179
  • Loading branch information
knocte committed Apr 23, 2021
1 parent ba5af9c commit 3322ab3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/GWallet.Backend/Marshalling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ module Marshalling =
let private currentVersion = VersionHelper.CURRENT_VERSION

let ExtractType(json: string): Type =
let fullTypeName = (JsonConvert.DeserializeObject<MarshallingWrapper<obj>> json).TypeName
Type.GetType(fullTypeName)
let wrapper = JsonConvert.DeserializeObject<MarshallingWrapper<obj>> json
if Object.ReferenceEquals(null, wrapper) then
failwith <| SPrintF1 "Failed to extract type from JSON: %s" json
Type.GetType wrapper.TypeName

let DeserializeCustom<'T>(json: string, settings: JsonSerializerSettings): 'T =
if (json = null) then
Expand Down

0 comments on commit 3322ab3

Please sign in to comment.