SpiceDb icon indicating copy to clipboard operation
SpiceDb copied to clipboard

`StartIndex cannot be less than zero` when importing schema from string or file

Open wub opened this issue 1 year ago • 3 comments

Hello, when running dotnet test (or trying to import my own schema from a file), I get this error:

System.ArgumentOutOfRangeException: StartIndex cannot be less than zero. (Parameter 'startIndex')
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex)
   at SpiceDb.Api.SchemaParser.Parse(String schema)
   at SpiceDb.SpiceDbClient.ImportSchemaFromStringAsync(String schema)

This is on M1 macOS Sonoma 14.1.1, .NET 7, SpiceDb 1.4.1. I'll clone the repo tonight and see if I can provide more details for you. Thanks!

wub avatar Nov 28 '23 21:11 wub

The schema code is mostly all from SpiceDB.Hierarchical.UI. It's not super pretty and feels bolted on. If you uncover the issue let me know. I usually do schema stuff via command line.

tanczosm avatar Dec 08 '23 03:12 tanczosm

Just an update, this is the current error with 1.38.x using client.ImportSchemaFromFileAsync("./schema.zed"). I'm just forking out to the CLI from within my app in the meantime.

 ---> System.AggregateException: One or more errors occurred. (Index was outside the bounds of the array.)
 ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SpiceDb.Api.SchemaParser.ReadPermissions(String txt, SchemaEntity entity)
   at SpiceDb.Api.SchemaParser.ParseEntity(Int32 _index, String text)
   at SpiceDb.Api.SchemaParser.Parse(String schema)
   at SpiceDb.SpiceDbClient.ImportSchemaFromStringAsync(String schema)
   at SpiceDb.SpiceDbClient.ImportSchemaFromFileAsync(String filePath)

wub avatar Nov 05 '24 21:11 wub

There is a ReadSchema and WriteSchema method. Have you tried those?

tanczosm avatar Nov 08 '24 16:11 tanczosm