Skip to content
Draft
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
1 change: 1 addition & 0 deletions internal/services/shared/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func TestRewriteError(t *testing.T) {
inputError: spiceerrors.NewWithSourceError(
fmt.Errorf("invalid schema definition"),
"definition document {\n relation viewer: user\n}",
"source",
1,
1,
),
Expand Down
6 changes: 3 additions & 3 deletions pkg/development/devcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,6 @@ func getDevError(cverr error, compiled *compiler.CompiledSchema, definitionOrCav
if cverr == nil || compiled == nil || definitionOrCaveat == nil {
return nil
}
path := compiled.GetPathToDefinitionOrPartialOrCaveat(definitionOrCaveat.GetName())
errWithSource, ok := spiceerrors.AsWithSourceError(cverr)
if ok {
// NOTE: zeroes are fine here to mean "unknown"
Expand All @@ -354,15 +353,16 @@ func getDevError(cverr error, compiled *compiler.CompiledSchema, definitionOrCav
Context: errWithSource.SourceCodeString,
Line: lineNumber,
Column: columnPosition,
Path: []string{path},
Path: []string{errWithSource.FileName},
}
}
return &devinterface.DeveloperError{
Message: cverr.Error(),
Kind: devinterface.DeveloperError_SCHEMA_ISSUE,
Source: devinterface.DeveloperError_SCHEMA,
Context: definitionOrCaveat.GetName(),
Path: []string{path},
// TODO: do we have any additional context here?
Path: []string{""},
}
}

Expand Down
17 changes: 4 additions & 13 deletions pkg/development/schema_position_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
if importPath, ok := r.importReferenceChain(nodeChain); ok {
importSource := input.Source(importPath)
return &SchemaReference{
ReferenceType: ReferenceTypeImport,
Source: source,
Position: position,
ReferenceType: ReferenceTypeImport,
Source: source,
Position: position,
// TODO: is this the path pointed at by the import, or is it the position of the import reference itself?
TargetSource: &importSource,
TargetPosition: &input.Position{LineNumber: 0, ColumnPosition: 0},
Text: importPath,
Expand All @@ -109,7 +110,7 @@
targetPosition = &input.Position{LineNumber: line, ColumnPosition: col}
}

targetSource := r.resolveTargetSource(partialName, source)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Lint Everything

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Ensure Docs are up to date

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / WASM Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / E2E (22.1.5)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Build Binary & Image

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (spanner)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (mysql)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 26.1.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 16)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 18)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 17)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 25.2.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 14)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Unit

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 15)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Run Go benchmarks

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 113 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Integration Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)
return &SchemaReference{
Source: source,
Position: position,
Expand Down Expand Up @@ -142,7 +143,7 @@
return nil, err
}

targetSource := r.resolveTargetSource(relation.Name, source)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Lint Everything

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Ensure Docs are up to date

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / WASM Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / E2E (22.1.5)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Build Binary & Image

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (spanner)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (mysql)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 26.1.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 16)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 18)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 17)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 25.2.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 14)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Unit

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 15)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Run Go benchmarks

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 146 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Integration Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

if def.IsPermission(relation.Name) {
return &SchemaReference{
Expand Down Expand Up @@ -209,7 +210,7 @@
targetSourceCode = fmt.Sprintf("%sdefinition %s {}", docComment, def.Name)
}

targetSource := r.resolveTargetSource(def.Name, source)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Lint Everything

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Ensure Docs are up to date

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / WASM Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / E2E (22.1.5)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Build Binary & Image

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (spanner)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (mysql)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 26.1.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 16)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 18)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 17)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 25.2.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 14)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Unit

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 15)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Run Go benchmarks

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 213 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Integration Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)
return &SchemaReference{
Source: source,
Position: position,
Expand Down Expand Up @@ -255,7 +256,7 @@
}
caveatSourceCode.WriteString(") {\n\t// ...\n}")

targetSource := r.resolveTargetSource(caveatDef.Name, source)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Lint Everything

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Ensure Docs are up to date

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / WASM Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / E2E (22.1.5)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Build Binary & Image

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (spanner)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (mysql)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 26.1.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 16)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 18)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 17)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 25.2.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 14)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Unit

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 15)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Run Go benchmarks

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 259 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Integration Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)
return &SchemaReference{
Source: source,
Position: position,
Expand All @@ -279,7 +280,7 @@
// Caveat parameter used in expression.
if caveatParamName, paramTypeString, caveatDef, ok := r.caveatParamChain(nodeChain, source, position); ok {
targetSourceCode := fmt.Sprintf("%s %s", caveatParamName, paramTypeString)
targetSource := r.resolveTargetSource(caveatDef.Name, source)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Lint Everything

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Ensure Docs are up to date

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / WASM Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / E2E (22.1.5)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Build Binary & Image

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (spanner)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (mysql)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 26.1.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 16)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 18)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 17)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (crdb, 25.2.0)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 14)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Unit

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Datastore Consistency Tests (postgres, 15)

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Run Go benchmarks

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)

Check failure on line 283 in pkg/development/schema_position_mapper.go

View workflow job for this annotation

GitHub Actions / Integration Tests

r.resolveTargetSource undefined (type *SchemaPositionMapper has no field or method resolveTargetSource)
return &SchemaReference{
Source: source,
Position: position,
Expand All @@ -296,16 +297,6 @@
return nil, nil
}

// resolveTargetSource returns the input.Source for the file where a definition or caveat
// is defined. For imported definitions, this will be the imported file path. For definitions
// in the root schema, this returns the fallback source.
func (r *SchemaPositionMapper) resolveTargetSource(name string, fallback input.Source) input.Source {
if defSource := r.schema.GetPathToDefinitionOrPartialOrCaveat(name); defSource != "" {
return input.Source(defSource)
}
return fallback
}

func (r *SchemaPositionMapper) lookupCaveat(caveatName string) (*core.CaveatDefinition, bool) {
c, err := r.typeSystem.GetCaveat(context.Background(), caveatName)
if err != nil {
Expand Down
13 changes: 11 additions & 2 deletions pkg/proto/core/v1/core.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions pkg/proto/core/v1/core_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pkg/schema/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,14 +423,16 @@
return asTypeError(spiceerrors.NewWithSourceError(
wrapped,
sourceCodeString,
sourcePosition.ZeroIndexedLineNumber+1, // +1 to make 1-indexed
sourcePosition.FileName,
sourcePosition.ZeroIndexedLineNumber+1, // +1 to make 1-indexed

Check warning on line 427 in pkg/schema/errors.go

View check run for this annotation

Codecov / codecov/patch

pkg/schema/errors.go#L426-L427

Added lines #L426 - L427 were not covered by tests
sourcePosition.ZeroIndexedColumnPosition+1, // +1 to make 1-indexed
))
}

return asTypeError(spiceerrors.NewWithSourceError(
wrapped,
sourceCodeString,
"",
0,
0,
))
Expand Down
35 changes: 0 additions & 35 deletions pkg/schemadsl/compiler/development.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,41 +55,6 @@ func (nc *NodeChain) String() string {
return out.String()
}

// GetPathToDefinitionOrPartialOrCaveat returns the input source for the AST node defining the given name.
// For definitions compiled from imports, this will be the imported file path (e.g. "users.zed").
// For definitions in the root schema, this will be the root source (e.g. "schema").
// Returns empty string if not found.
func (cs *CompiledSchema) GetPathToDefinitionOrPartialOrCaveat(name string) string {
for _, child := range cs.rootNode.GetChildren() {
nodeType := child.GetType()
var predicateName string
switch nodeType {
case dslshape.NodeTypeDefinition:
predicateName = dslshape.NodeDefinitionPredicateName
case dslshape.NodeTypeCaveatDefinition:
predicateName = dslshape.NodeCaveatDefinitionPredicateName
case dslshape.NodeTypePartial:
predicateName = dslshape.NodePartialPredicateName
default:
continue
}

defName, err := child.GetString(predicateName)
if err != nil {
continue
}

if defName == name {
source, err := child.GetString(dslshape.NodePredicateSource)
if err != nil {
return ""
}
return source
}
}
return ""
}

// PartialNodePosition returns the start rune position and source of the partial
// definition with the given name. Returns (-1, -1, "") if not found.
func (cs *CompiledSchema) PartialNodePosition(name string) (int, int) {
Expand Down
10 changes: 10 additions & 0 deletions pkg/schemadsl/compiler/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@
return nil
}

if !dslNode.Has(dslshape.NodePredicateSource) {
return nil
}

Check warning on line 341 in pkg/schemadsl/compiler/translator.go

View check run for this annotation

Codecov / codecov/patch

pkg/schemadsl/compiler/translator.go#L340-L341

Added lines #L340 - L341 were not covered by tests

sourceRange, err := dslNode.Range(mapper)
if err != nil {
return nil
Expand All @@ -355,9 +359,15 @@
uintCol = 0
}

filename, err := dslNode.GetString(dslshape.NodePredicateSource)
if err != nil {
return nil
}

Check warning on line 365 in pkg/schemadsl/compiler/translator.go

View check run for this annotation

Codecov / codecov/patch

pkg/schemadsl/compiler/translator.go#L364-L365

Added lines #L364 - L365 were not covered by tests

return &core.SourcePosition{
ZeroIndexedLineNumber: uintLine,
ZeroIndexedColumnPosition: uintCol,
FileName: filename,
}
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/spiceerrors/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type WithSourceError struct {
// SourceCodeString is the input source code string for the error.
SourceCodeString string

// FileName is the filename where the error was found.
FileName string

// LineNumber is the (1-indexed) line number of the error, or 0 if unknown.
LineNumber uint64

Expand All @@ -42,8 +45,8 @@ func (err *WithSourceError) Unwrap() error {
}

// NewWithSourceError creates and returns a new WithSourceError.
func NewWithSourceError(err error, sourceCodeString string, oneIndexedLineNumber uint64, oneIndexedColumnPosition uint64) *WithSourceError {
return &WithSourceError{err, sourceCodeString, oneIndexedLineNumber, oneIndexedColumnPosition}
func NewWithSourceError(err error, sourceCodeString, fileName string, oneIndexedLineNumber uint64, oneIndexedColumnPosition uint64) *WithSourceError {
return &WithSourceError{err, sourceCodeString, fileName, oneIndexedLineNumber, oneIndexedColumnPosition}
}

// AsWithSourceError returns the error as an WithSourceError, if applicable.
Expand Down
6 changes: 6 additions & 0 deletions pkg/validationfile/blocks/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ func (a *Assertion) UnmarshalYAML(node *yamlv3.Node) error {
return spiceerrors.NewWithSourceError(
fmt.Errorf("error parsing assertion `%s`", trimmed),
trimmed,
// TODO: this should point at the filename. is there a way to get that context here?
"",
line,
column,
)
Expand All @@ -106,6 +108,8 @@ func (a *Assertion) UnmarshalYAML(node *yamlv3.Node) error {
return spiceerrors.NewWithSourceError(
fmt.Errorf("error parsing relationship in assertion `%s`: %w", trimmed, err),
trimmed,
// TODO: this should point at the filename. is there a way to get that context here?
"",
line,
column,
)
Expand All @@ -120,6 +124,8 @@ func (a *Assertion) UnmarshalYAML(node *yamlv3.Node) error {
return spiceerrors.NewWithSourceError(
fmt.Errorf("error parsing caveat context in assertion `%s`: %w", trimmed, err),
trimmed,
// TODO: this should point at the filename. is there a way to get that context here?
"",
line,
column,
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/validationfile/blocks/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func convertYamlError(err error) error {
return spiceerrors.NewWithSourceError(
errors.New(message),
source,
// TODO: this should point at the filename. is there a way to get that context here?
"",
lineNumber,
0,
)
Expand Down
14 changes: 10 additions & 4 deletions pkg/validationfile/blocks/expectedrelations.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func (ors *ObjectRelation) UnmarshalYAML(node *yamlv3.Node) error {
return spiceerrors.NewWithSourceError(
fmt.Errorf("could not parse %s: %w", ors.ObjectRelationString, err),
ors.ObjectRelationString,
// TODO: this should point at the filename. is there a way to get that context here?
"",
line,
column,
)
Expand Down Expand Up @@ -144,6 +146,8 @@ func (es *ExpectedSubject) UnmarshalYAML(node *yamlv3.Node) error {
return spiceerrors.NewWithSourceError(
subErr,
subErr.SourceCodeString,
// TODO: this should point at the filename. is there a way to get that context here?
"",
line+subErr.LineNumber,
column+subErr.ColumnPosition,
)
Expand All @@ -154,6 +158,8 @@ func (es *ExpectedSubject) UnmarshalYAML(node *yamlv3.Node) error {
return spiceerrors.NewWithSourceError(
onrErr,
onrErr.SourceCodeString,
// TODO: this should point at the filename. is there a way to get that context here?
"",
line+onrErr.LineNumber,
column+onrErr.ColumnPosition,
)
Expand Down Expand Up @@ -192,13 +198,13 @@ func (vs ValidationString) Subject() (*SubjectWithExceptions, *spiceerrors.WithS
groups := vsSubjectWithExceptionsOrCaveatRegex.FindStringSubmatch(subjectStr)
if len(groups) == 0 {
bracketedSubjectString := "[" + subjectStr + "]"
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid subject: `%s`", subjectStr), bracketedSubjectString, 0, 0)
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid subject: `%s`", subjectStr), bracketedSubjectString, "", 0, 0)
}

subjectONRString := groups[slices.Index(vsSubjectWithExceptionsOrCaveatRegex.SubexpNames(), "subject_onr")]
subjectONR, err := tuple.ParseSubjectONR(subjectONRString)
if err != nil {
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid subject: `%s`: %w", subjectONRString, err), subjectONRString, 0, 0)
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid subject: `%s`: %w", subjectONRString, err), subjectONRString, "", 0, 0)
}

exceptionsString := strings.TrimSpace(groups[slices.Index(vsSubjectWithExceptionsOrCaveatRegex.SubexpNames(), "exceptions")])
Expand All @@ -216,7 +222,7 @@ func (vs ValidationString) Subject() (*SubjectWithExceptions, *spiceerrors.WithS

exceptionONR, err := tuple.ParseSubjectONR(strings.TrimSpace(exceptionString))
if err != nil {
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid subject: `%s`: %w", exceptionString, err), exceptionString, 0, 0)
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid subject: `%s`: %w", exceptionString, err), exceptionString, "", 0, 0)
}

exceptions = append(exceptions, SubjectAndCaveat{exceptionONR, isCaveated})
Expand Down Expand Up @@ -244,7 +250,7 @@ func (vs ValidationString) ONRS() ([]tuple.ObjectAndRelation, *spiceerrors.WithS
for _, onrString := range onrStrings {
found, err := tuple.ParseONR(onrString)
if err != nil {
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid resource and relation: `%s`: %w", onrString, err), onrString, 0, 0)
return nil, spiceerrors.NewWithSourceError(fmt.Errorf("invalid resource and relation: `%s`: %w", onrString, err), onrString, "", 0, 0)
}

onrs = append(onrs, found)
Expand Down
Loading
Loading