Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Get innerException message Recursively #630

Merged
merged 10 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions neo-cli/CLI/MainService.Contracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ private void OnDeployCommand(string filePath, string manifestPath = null)
{
tx = CurrentWallet.MakeTransaction(script);
}
catch (InvalidOperationException)
catch (InvalidOperationException e)
{
Console.WriteLine("Engine faulted.");
Console.WriteLine("Error: " + GetExceptionMessage(e));
return;
}
Console.WriteLine($"Script hash: {scriptHash.ToString()}");
Expand Down Expand Up @@ -68,9 +68,9 @@ private void OnInvokeCommand(UInt160 scriptHash, string operation, JArray contra
{
tx = CurrentWallet.MakeTransaction(tx.Script, signers.Length > 0 ? signers[0].Account : null, signers);
}
catch (InvalidOperationException)
catch (InvalidOperationException e)
{
Console.WriteLine("Error: insufficient balance.");
Console.WriteLine("Error: " + GetExceptionMessage(e));
return;
}
if (!ReadUserInput("Relay tx(no|yes)").IsYes())
Expand Down
4 changes: 2 additions & 2 deletions neo-cli/CLI/MainService.NEP5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ private void OnTransferCommand(UInt160 tokenHash, UInt160 to, decimal amount)
}
}, from: null);
}
catch (InvalidOperationException)
catch (InvalidOperationException e)
{
Console.WriteLine("Error: insufficient balance.");
Console.WriteLine("Error: " + GetExceptionMessage(e));
return;
}
if (!ReadUserInput("Relay tx(no|yes)").IsYes())
Expand Down
2 changes: 1 addition & 1 deletion neo-cli/CLI/MainService.Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void OnRelayCommand(JObject jsonObjectToRelay)
}
catch (Exception e)
{
Console.WriteLine($"One or more errors occurred:{Environment.NewLine}{e.Message}");
Console.WriteLine("Error: " + GetExceptionMessage(e));
}
}
}
Expand Down
16 changes: 5 additions & 11 deletions neo-cli/CLI/MainService.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private void OnSignCommand(JObject jsonObjectToSign)
}
catch (Exception e)
{
Console.WriteLine($"One or more errors occurred:{Environment.NewLine}{e.Message}");
Console.WriteLine("Error: " + GetExceptionMessage(e));
}
}

Expand Down Expand Up @@ -523,26 +523,20 @@ private void SignAndSendTx(Transaction tx)
{
context = new ContractParametersContext(tx);
}
catch (InvalidOperationException ex)
catch (InvalidOperationException e)
{
Console.WriteLine($"Error creating contract params: {ex}");
Console.WriteLine($"Error creating contract params: " + GetExceptionMessage(e));
throw;
}
CurrentWallet.Sign(context);
string msg;
if (context.Completed)
{
tx.Witnesses = context.GetWitnesses();

NeoSystem.Blockchain.Tell(tx);

msg = $"Signed and relayed transaction with hash={tx.Hash}";
Console.WriteLine(msg);
Console.WriteLine($"Signed and relayed transaction with hash={tx.Hash}");
return;
}

msg = $"Failed sending transaction with hash={tx.Hash}";
Console.WriteLine(msg);
Console.WriteLine($"Failed sending transaction with hash={tx.Hash}");
}
}
}
2 changes: 1 addition & 1 deletion neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ static string GetExceptionMessage(Exception exception)

if (exception.InnerException != null)
{
return exception.InnerException.Message;
return GetExceptionMessage(exception.InnerException);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Require both changes? or it's enough with the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns "Exceptions has been thrown by the target of an invocation" if calling current GetExceptionMessage, because Deploy (catch) -> MakeTransaction (throw) -> ApplicationEngine.Run (throw) -> createContract (throw)
b3d93acdeb6f2e17360978c1f3bca78

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move GetExceptionMessage to ConsoleServiceBase and change

Console.WriteLine($"error: {ex.InnerException.Message}");

}

return exception.Message;
Expand Down