Skip to content

Commit

Permalink
Add check traces to assertion errors for better debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Jun 23, 2023
1 parent 5b4dfd1 commit 4442539
Show file tree
Hide file tree
Showing 6 changed files with 479 additions and 157 deletions.
14 changes: 8 additions & 6 deletions pkg/development/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ func runAssertions(devContext *DevContext, assertions []blocks.Assertion, expect
}
} else if cr.Permissionship != expected {
failures = append(failures, &devinterface.DeveloperError{
Message: fmt.Sprintf(fmtString, assertion.RelationshipWithContextString),
Source: devinterface.DeveloperError_ASSERTION,
Kind: devinterface.DeveloperError_ASSERTION_FAILED,
Context: assertion.RelationshipWithContextString,
Line: uint32(assertion.SourcePosition.LineNumber),
Column: uint32(assertion.SourcePosition.ColumnPosition),
Message: fmt.Sprintf(fmtString, assertion.RelationshipWithContextString),
Source: devinterface.DeveloperError_ASSERTION,
Kind: devinterface.DeveloperError_ASSERTION_FAILED,
Context: assertion.RelationshipWithContextString,
Line: uint32(assertion.SourcePosition.LineNumber),
Column: uint32(assertion.SourcePosition.ColumnPosition),
CheckDebugInformation: cr.DispatchDebugInfo,
CheckResolvedDebugInformation: cr.V1DebugInfo,
})
}
}
Expand Down
36 changes: 36 additions & 0 deletions pkg/development/wasm/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func TestRunAssertionsAndValidationOperations(t *testing.T) {
validationYaml string
assertionsYaml string
expectedError *devinterface.DeveloperError
expectCheckTraces bool
expectedValidationYaml string
}

Expand All @@ -425,6 +426,7 @@ func TestRunAssertionsAndValidationOperations(t *testing.T) {
"",
"",
nil,
false,
"{}\n",
},
{
Expand All @@ -440,6 +442,7 @@ func TestRunAssertionsAndValidationOperations(t *testing.T) {
Context: "asdkjhg",
Line: 1,
},
false,
"",
},
{
Expand All @@ -455,6 +458,7 @@ func TestRunAssertionsAndValidationOperations(t *testing.T) {
Context: "asdhasj",
Line: 1,
},
false,
"",
},
{
Expand All @@ -474,6 +478,7 @@ assertFalse: garbage
Source: devinterface.DeveloperError_ASSERTION,
Line: 5,
},
false,
"",
},
{
Expand All @@ -495,6 +500,7 @@ assertFalse: garbage
Column: 0,
Context: "garbage",
},
false,
"",
},
{
Expand All @@ -512,6 +518,7 @@ assertFalse: garbage
Column: 3,
Context: "something",
},
false,
"",
},
{
Expand All @@ -534,6 +541,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
true,
"{}\n",
},
{
Expand All @@ -556,6 +564,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
true,
"{}\n",
},
{
Expand All @@ -576,6 +585,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
false,
"{}\n",
},
{
Expand All @@ -596,6 +606,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
false,
"{}\n",
},
{
Expand All @@ -620,6 +631,7 @@ assertFalse: garbage
Line: 1,
Column: 1,
},
false,
`document:somedoc#view:
- '[user:jimmy] is <document:somedoc#writer>'
`,
Expand Down Expand Up @@ -648,6 +660,7 @@ assertFalse: garbage
Line: 3,
Column: 3,
},
false,
`document:somedoc#view:
- '[user:jimmy] is <document:somedoc#writer>'
`,
Expand Down Expand Up @@ -675,6 +688,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
false,
``,
},
{
Expand All @@ -700,6 +714,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
false,
``,
},
{
Expand All @@ -725,6 +740,7 @@ assertFalse: garbage
Line: 2,
Column: 3,
},
false,
`document:somedoc#view:
- '[user:jimmy] is <document:somedoc#writer>'
`,
Expand Down Expand Up @@ -773,6 +789,7 @@ assertFalse:
- 'document:somedoc#viewer@user:sarah with {"somecondition": "45"}'
`,
nil,
false,
`document:somedoc#view:
- '[user:fred[...]] is <document:somedoc#viewer>'
- '[user:jake] is <document:somedoc#viewer>'
Expand Down Expand Up @@ -801,6 +818,7 @@ assertFalse:
- document:somedoc#writer@user:jimmy
`,
nil,
false,
`document:somedoc#view:
- '[user:jimmy] is <document:somedoc#viewer>/<document:somedoc#writer>'
`,
Expand Down Expand Up @@ -832,6 +850,7 @@ assertFalse:
Line: 2,
Column: 3,
},
false,
`document:somedoc#view:
- '[user:jimmy] is <document:somedoc#viewer>/<document:somedoc#writer>'
`,
Expand All @@ -850,6 +869,7 @@ assertFalse:
Source: devinterface.DeveloperError_RELATIONSHIP,
Context: `document:somedoc#writer@user:jimmy`,
},
false,
``,
},
{
Expand All @@ -867,6 +887,7 @@ assertFalse:
Source: devinterface.DeveloperError_RELATIONSHIP,
Context: `document:somedoc#writer@user:jimmy`,
},
false,
``,
},
{
Expand All @@ -893,6 +914,7 @@ assertFalse:
assertFalse:
- document:somedoc#writer@user:somegal`,
nil,
false,
`document:somedoc#view:
- '[user:*] is <document:somedoc#viewer>'
- '[user:jimmy] is <document:somedoc#writer>'
Expand All @@ -919,6 +941,7 @@ assertFalse:
assertFalse:
- document:somedoc#view@user:jimmy`,
nil,
false,
`document:somedoc#view:
- '[user:* - {user:jimmy}] is <document:somedoc#viewer>'
`,
Expand Down Expand Up @@ -947,6 +970,7 @@ assertFalse:
- document:somedoc#view@user:jimmy
- document:somedoc#view@user:sarah`,
nil,
false,
`document:somedoc#view:
- '[user:* - {user:jimmy, user:sarah}] is <document:somedoc#viewer>'
`,
Expand Down Expand Up @@ -976,6 +1000,7 @@ assertFalse:
- document:somedoc#empty@user:jill
- document:somedoc#empty@user:tom`,
nil,
false,
"document:somedoc#empty: []\ndocument:somedoc#view:\n- '[user:jill] is <document:somedoc#viewer>'\n- '[user:tom] is <document:somedoc#viewer>'\n",
},
{
Expand Down Expand Up @@ -1005,6 +1030,7 @@ assertFalse:
Line: 2,
Column: 3,
},
false,
"document:somedoc#view:\n- '[user:jill] is <document:somedoc#viewer>'\n- '[user:tom] is <document:somedoc#viewer>'\n",
},

Expand Down Expand Up @@ -1043,6 +1069,7 @@ assertFalse:
Kind: devinterface.DeveloperError_MISSING_EXPECTED_RELATIONSHIP,
Context: "[user:sarah] is <document:somedoc#viewer>",
},
false,
`document:somedoc#view:
- '[user:sarah[...]] is <document:somedoc#viewer>'
`,
Expand Down Expand Up @@ -1097,6 +1124,15 @@ assertFalse:
errors = append(errors, response.GetOperationsResults().Results[1].GetValidationResult().ValidationErrors...)
}
}

if tc.expectCheckTraces {
require.NotNil(t, errors[0].CheckDebugInformation)
require.NotNil(t, errors[0].CheckResolvedDebugInformation)

errors[0].CheckDebugInformation = nil
errors[0].CheckResolvedDebugInformation = nil
}

testutil.RequireProtoEqual(t, tc.expectedError, errors[0], "mismatch on errors")
} else {
require.Equal(0, len(response.GetOperationsResults().Results[0].GetAssertionsResult().ValidationErrors), "Failed assertion", response.GetOperationsResults().Results[0].GetAssertionsResult().ValidationErrors)
Expand Down
Loading

0 comments on commit 4442539

Please sign in to comment.