Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEO3] there is not JSON Format error show when protocol.json is with json format error #1412

Closed
cloud8little opened this issue Jan 15, 2020 · 8 comments

Comments

@cloud8little
Copy link
Contributor

cloud8little commented Jan 15, 2020

Describe the bug
when start a neo-cli, I delete a "}" in the last line of the protocol.json by mistake, and unaware of it. then start neo-cli, it shows "Object reference not set to an instance of an object" error, with all the error messages, i can not get the information of the json error.
If config.json is with format error, there shows "Can not parse json", which is expected.

To Reproduce
Steps to reproduce the behavior:
neo-cli: master 51cd29fbe21abb9e1f17f64e5c6d21bc7decbbb9
neo: master ab4830c
neo-vm: master be2ac36bf35a3033d828e0ba0630d390599c487d
MillisecondsPerBlock is 15000.

  1. Start a single consensus node.
  2. Start a external node.
  3. modify the protocol.json, such as delete a "}" in the last line.
{
  "ProtocolConfiguration": {
    "Magic": 20200109,
    "MillisecondsPerBlock": 15000,
    "StandbyValidators": [
      "03ac37bdaa57563af356a787da8503db3bdfbde1f072c3bc3a6433b1929e190e4d"
    ],
    "SeedList": [
      "localhost:13333"
    ]
  }
  1. start neo-cli, it shows:
neo> Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Neo.Plugins.Logger.Neo.Plugins.ILogPlugin.Log(String source, LogLevel level, String message)
   at Neo.Utility.Log(String source, LogLevel level, String message) in D:\NEO\Github\neo\src\neo\Utility.cs:line 25
   at Neo.Plugins.Plugin.LoadPlugin(Assembly assembly) in D:\NEO\Github\neo\src\neo\Plugins\Plugin.cs:line 134
   at Neo.Plugins.Plugin.LoadPlugins(NeoSystem system) in D:\NEO\Github\neo\src\neo\Plugins\Plugin.cs:line 154
   at Neo.NeoSystem..ctor(String storageEngine) in D:\NEO\Github\neo\src\neo\NeoSystem.cs:line 32
   at Neo.CLI.MainService.Start(String[] args)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Expected behavior
here is error message of neo-cli 2.10.3 for reference.
039650e3bd6792038cf906bfa562782

7081bd82be1329adeaf741aabaa6b19

Screenshots
ee2798aca4644e2f446ee547b3794b7
e620bbb5d4f4037f78b2e279e8e948b

Platform:

  • OS: Windows 10 x64
@shargon
Copy link
Member

shargon commented Jan 15, 2020

The problem is with plugins, right? with protocol I can see the json error

@shargon
Copy link
Member

shargon commented Jan 15, 2020

I received the JsonReaderException in all cases... plugins, config and protocol.

image

@cloud8little
Copy link
Contributor Author

@shargon the message shows as below, from the message we thought it was plugins problem. while in fact, there is only protocol.json format error. when i correct it, there is no error message show.

neo> Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Neo.Plugins.Logger.Neo.Plugins.ILogPlugin.Log(String source, LogLevel level, String message)
   at Neo.Utility.Log(String source, LogLevel level, String message) in D:\NEO\Github\neo\src\neo\Utility.cs:line 25
   at Neo.Plugins.Plugin.LoadPlugin(Assembly assembly) in D:\NEO\Github\neo\src\neo\Plugins\Plugin.cs:line 134
   at Neo.Plugins.Plugin.LoadPlugins(NeoSystem system) in D:\NEO\Github\neo\src\neo\Plugins\Plugin.cs:line 154
   at Neo.NeoSystem..ctor(String storageEngine) in D:\NEO\Github\neo\src\neo\NeoSystem.cs:line 32
   at Neo.CLI.MainService.Start(String[] args)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

@cloud8little
Copy link
Contributor Author

@shargon Yes, your right. different plugins combinations with different error message.
no plugins

neo> Unhandled exception. System.TypeInitializationException: The type initializer for 'Neo.Ledger.Blockchain' threw an exception.
 ---> System.FormatException: Could not parse the JSON file.
 ---> System.Text.Json.JsonReaderException: Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. LineNumber: 12 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, Utf8JsonReader reader, MetadataDb& database, StackRowStack& stack)
   at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedBytes)
   at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 json, JsonDocumentOptions options)
   at System.Text.Json.JsonDocument.Parse(String json, JsonDocumentOptions options)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.ParseStream(Stream input)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.Parse(Stream input)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Neo.Utility.LoadConfig(String config) in D:\NEO\Github\neo\src\neo\Utility.cs:line 18
   at Neo.ProtocolSettings.get_Default() in D:\NEO\Github\neo\src\neo\ProtocolSettings.cs:line 36
   at Neo.Ledger.Blockchain..cctor() in D:\NEO\Github\neo\src\neo\Ledger\Blockchain.cs:line 32
   --- End of inner exception stack trace ---
   at Neo.Ledger.Blockchain.Props(NeoSystem system, IStore store)
   at Neo.NeoSystem..ctor(String storageEngine) in D:\NEO\Github\neo\src\neo\NeoSystem.cs:line 14
   at Neo.CLI.MainService.Start(String[] args)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

only with LevelDBStore plugins

D:\NEO\NEO3\privatenet\test-neo-devpack-latest\external>dotnet neo-cli.dll
NEO-CLI v3.0.0-preview1  -  NEO v3.0.0-preview1  -  NEO-VM v3.0.0-preview1

neo> Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'path')
   at System.IO.Path.GetFullPath(String path)
   at Neo.IO.Data.LevelDB.DB.Open(String name, Options options)
   at Neo.Plugins.Storage.Store..ctor(String path)
   at Neo.Plugins.Storage.LevelDBStore.GetStore()
   at Neo.NeoSystem..ctor(String storageEngine) in D:\NEO\Github\neo\src\neo\NeoSystem.cs:line 14
   at Neo.CLI.MainService.Start(String[] args)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

with LevelDBStore and SystemLog plugins

D:\NEO\NEO3\privatenet\test-neo-devpack-latest\external>dotnet neo-cli.dll
NEO-CLI v3.0.0-preview1  -  NEO v3.0.0-preview1  -  NEO-VM v3.0.0-preview1

neo> Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Neo.Plugins.Logger.Neo.Plugins.ILogPlugin.Log(String source, LogLevel level, String message)
   at Neo.Utility.Log(String source, LogLevel level, String message) in D:\NEO\Github\neo\src\neo\Utility.cs:line 25
   at Neo.Plugins.Plugin.LoadPlugin(Assembly assembly) in D:\NEO\Github\neo\src\neo\Plugins\Plugin.cs:line 134
   at Neo.Plugins.Plugin.LoadPlugins(NeoSystem system) in D:\NEO\Github\neo\src\neo\Plugins\Plugin.cs:line 154
   at Neo.NeoSystem..ctor(String storageEngine) in D:\NEO\Github\neo\src\neo\NeoSystem.cs:line 32
   at Neo.CLI.MainService.Start(String[] args)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__139_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

@cloud8little
Copy link
Contributor Author

@shargon do you mean that plugins such as LevelDBStore or SystemLog should capture the exception and hanlde it, for example show it on the command line?

@shargon
Copy link
Member

shargon commented Jan 15, 2020

With an invalid JSon for LevelDBStore I receive this

Unhandled exception. Unhandled exception. System.FormatException: Could not parse the JSON file.
 ---> System.Text.Json.JsonReaderException: Expected depth to be zero at the end of the JSON payload. There is an open JSON object or array that should be closed. LineNumber: 1 | BytePositionInLine: 0.
   at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
   at System.Text.Json.Utf8JsonReader.ReadSingleSegment()
   at System.Text.Json.Utf8JsonReader.Read()
   at System.Text.Json.JsonDocument.Parse(ReadOnlySpan`1 utf8JsonSpan, Utf8JsonReader reader, MetadataDb& database, StackRowStack& stack)
   at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 utf8Json, JsonReaderOptions readerOptions, Byte[] extraRentedBytes)
   at System.Text.Json.JsonDocument.Parse(ReadOnlyMemory`1 json, JsonDocumentOptions options)
   at System.Text.Json.JsonDocument.Parse(String json, JsonDocumentOptions options)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.ParseStream(Stream input)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationFileParser.Parse(Stream input)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationProvider.Load(Stream stream)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.HandleException(ExceptionDispatchInfo info)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
   at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
   at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
   at Neo.Plugins.Plugin.GetConfiguration() in C:\Sources\Neo\neo\src\neo\Plugins\Plugin.cs:line 119
   at Neo.Plugins.Storage.LevelDBStore.Configure() in C:\Sources\Neo\neo-plugins\src\LevelDBStore\Plugins\Storage\LevelDBStore.cs:line 11
   at Neo.Plugins.Plugin..ctor() in C:\Sources\Neo\neo\src\neo\Plugins\Plugin.cs:line 57
   at Neo.Plugins.Storage.LevelDBStore..ctor()
   at Neo.Program.Main(String[] args) in C:\Sources\Neo\neo-cli\neo-cli\Program.cs:line 28

Which json did you use?

@cloud8little
Copy link
Contributor Author

@shargon protocol.json as below, lack of "}" in the last line. and also I used the LevelDBStore build with latest neo(ab4830c #1403 )

{
  "ProtocolConfiguration": {
    "Magic": 20200109,
    "MillisecondsPerBlock": 15000,
    "StandbyValidators": [
      "03ac37bdaa57563af356a787da8503db3bdfbde1f072c3bc3a6433b1929e190e4d"
    ],
    "SeedList": [
      "localhost:13333"
    ]
  }

@shargon
Copy link
Member

shargon commented Feb 17, 2020

Closed because the fix (#1426) was closed

@shargon shargon closed this as completed Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants