Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fab48c54
Commit
fab48c54
authored
Jan 27, 2021
by
Enrique Alcantara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document using assertions to detect unsatisfied conditions
parent
31bf3639
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
3 deletions
+50
-3
doc/development/transient/prevention-patterns.md
doc/development/transient/prevention-patterns.md
+50
-3
No files found.
doc/development/transient/prevention-patterns.md
View file @
fab48c54
...
...
@@ -42,3 +42,50 @@ Including when that expanded content is:
-
**Invisible**
(
`display: none;`
). Some JavaScript requires the element to be visible to work properly (eg.: when taking measurements).
-
**Dynamic content**
(AJAX/DOM manipulation).
### Using assertions to detect transient bugs caused by unmet conditions
Transient bugs happen in the context of code that executes under the assumption
that the application’s state meets one or more conditions. We may write a feature
that assumes a server-side API response always include a group of attributes or that
an operation only executes when the application has successfully transitioned to a new
state.
Transient bugs are difficult to debug because there isn’t any mechanism that alerts
the user or the developer about unsatisfied conditions. These conditions are usually
not expressed explicitly in the code. A useful debugging technique for such situations
is placing assertions to make any assumption explicit. They can help detect the cause
which unmet condition causes the bug.
**Asserting pre-conditions on state mutations**
A common scenario that leads to transient bugs is when there is a polling service
that should mutate state only if a user operation is completed. We can use
assertions to make this pre-condition explicit:
```
javascript
// This action is called by a polling service. It assumes that all pre-conditions
// are satisfied by the time the action is dispatched.
export
const
updateMergeableStatus
=
({
commit
},
payload
)
=>
{
commit
(
types
.
SET_MERGEABLE_STATUS
,
payload
);
};
// We can make any pre-condition explicit by adding an assertion
export
const
updateMergeableStatus
=
({
state
,
commit
},
payload
)
=>
{
console
.
assert
(
state
.
isResolvingDiscussion
===
true
,
'
Resolve discussion request must be completed before updating mergeable status
'
);
commit
(
types
.
SET_MERGEABLE_STATUS
,
payload
);
};
```
**Asserting API contracts**
Another useful way of using assertions is to detect if the response payload returned
by the server-side endpoint satisfies the API contract.
**Related reading**
[
Debug it!
](
https://pragprog.com/titles/pbdp/debug-it/
)
explores techniques to diagnose
and fix non-determinstic bugs and write software that is easier to debug.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment