Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 05d609b

Browse files
committed
Feature/expose exceptions (#2)
* expose exceptions * bump version * tests * changelog * docs usage exceptions * editorconfig * makefile * remove build_docs script * readme make commands
1 parent c3858b0 commit 05d609b

File tree

13 files changed

+169
-10
lines changed

13 files changed

+169
-10
lines changed

.editorconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is for unifying the coding style for different editors and IDEs.
2+
# More information at http://EditorConfig.org
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Unix-style newlines with a newline ending every file
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
# 4 space indentation
15+
[*.py]
16+
indent_style = space
17+
indent_size = 4
18+
19+
# Matches the exact files either package.json or .travis.yml
20+
[{package.json,.travis.yml}]
21+
indent_style = space
22+
indent_size = 2
23+
24+
# Override for Makefile
25+
[{Makefile, makefile, GNUmakefile}]
26+
indent_style = tab
27+
indent_size = 4

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.1.1
2+
==================
3+
4+
* Expose V8 exceptions
5+
6+
17
0.1.0
28
==================
39

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
clean:
2+
rm -fr dist/ doc/_build/
3+
4+
docs:
5+
cd docs && make clean && make html
6+
7+
test:
8+
python runtests.py
9+
10+
build-examples:
11+
export NODE_ENV=production
12+
cd examples/flux && npm install && npm run bundle
13+
cd examples/simple && npm install && npm run bundle
14+
python build_examples.py
15+
16+
sdist: test clean
17+
python setup.py sdist
18+
19+
release: test clean
20+
python setup.py sdist upload
21+
22+
.PHONY: clean docs test build-examples sdist release

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ Read the [docs](http://python-react-v8.readthedocs.org/en/latest/).
5656
* [Simple](https://github.com/nitely/python-react-v8/tree/master/examples/simple)
5757

5858

59+
## Build examples
60+
61+
```
62+
$ make build-examples
63+
```
64+
65+
66+
## Tests
67+
68+
```
69+
$ make test
70+
```
71+
72+
5973
## License
6074

6175
MIT

build_docs.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/api.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ Utils Module
1616

1717
.. automodule:: react.utils
1818
:members: set_up, load_libs, run_script
19+
20+
21+
Excepts Module
22+
--------------
23+
24+
.. automodule:: react.excepts
25+
:members:

docs/usage.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,44 @@ But there are two things to have in mind:
6969
it gets exposed as a JS object within the HTML.
7070
2. The data passed to react should be exactly the same as the data provided
7171
by the API endpoint for that view, so the query should be the same.
72+
73+
74+
Multiple stores
75+
---------------
76+
77+
::
78+
79+
# ...
80+
data = {
81+
'postIts': orm.query().all().only('id', 'text'),
82+
'comments': orm.query().all().only('id', 'created_by', 'comment_html')
83+
}
84+
# ...
85+
86+
Seriously.
87+
88+
89+
Handling errors
90+
---------------
91+
92+
::
93+
94+
import react
95+
96+
# ...
97+
try:
98+
content = react_.render()
99+
except react.excepts.V8Error as err:
100+
logger.error(err)
101+
content = ''
102+
# ...
103+
104+
When handling exceptions, there is not much to do other
105+
than set an empty content and let react render it client-side.
106+
107+
The data can still be pre-loaded, assuming the error wasn't
108+
thrown by the load function.
109+
110+
It may be a good idea to log the data (as json) to replicate
111+
the error later. Since most of the logic is the same client-side,
112+
once you have replicated it, it can be debugged in the web-browser.

react/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
from .react import React, set_up
44
from . import utils
5+
from . import excepts
56

67
__all__ = [
78
'set_up',
89
'React',
9-
'utils']
10+
'utils',
11+
'excepts']
1012

11-
__version__ = '0.1.0'
13+
__version__ = '0.1.1'

react/excepts.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from v8cffi.exceptions import (
4+
V8Error,
5+
V8JSError,
6+
V8MemoryError,
7+
V8UnknownError)
8+
9+
__all__ = [
10+
'V8Error',
11+
'V8JSError',
12+
'V8MemoryError',
13+
'V8UnknownError']

react/react.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def set_up():
2424
global V8 context.\
2525
Should be called once\
2626
in the app lifetime.
27+
28+
:raises react.excepts.V8Error: if there was\
29+
an error running the JS script. This should\
30+
usually not be handled
2731
"""
2832
utils.set_up()
2933

@@ -65,6 +69,8 @@ def render(self):
6569
"""
6670
:return: Result of the JS render call
6771
:rtype: str
72+
:raises react.excepts.V8Error: if there was\
73+
an error running the JS script
6874
"""
6975
return utils.run_script(self.build_js_script())
7076

0 commit comments

Comments
 (0)