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

Don't display "PreventUpdate" errors in the dev tools UI #162

Merged
merged 3 commits into from
Apr 18, 2019
Merged
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
9 changes: 7 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,13 @@ function updateOutput(
// update the status of this request
updateRequestQueue(true, res.status);

// eject into `catch` handler below
throw res;
/*
* eject into `catch` handler below to display error
* message in ui
*/
if (res.status !== STATUS.PREVENT_UPDATE) {
throw res;
}
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export const OAUTH_COOKIE_NAME = 'plotly_oauth_token';

export const STATUS = {
OK: 200,
PREVENT_UPDATE: 204,
CLIENTSIDE_ERROR: 'CLIENTSIDE_ERROR',
};
40 changes: 39 additions & 1 deletion tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,44 @@ def update_output(n_clicks):
self.wait_for_element_by_css_selector('.test-devtools-error-toggle').click()
self.percy_snapshot('devtools - python exception - 2 errors open')

def test_devtools_prevent_update(self):
# raising PreventUpdate shouldn't display the error message
app = dash.Dash(__name__)


app.layout = html.Div([
html.Button(id='python', children='Prevent update', n_clicks=0),
html.Div(id='output')
])

@app.callback(
Output('output', 'children'),
[Input('python', 'n_clicks')])
def update_output(n_clicks):
if n_clicks == 1:
raise PreventUpdate
if n_clicks == 2:
raise Exception('An actual python exception')

return 'button clicks: {}'.format(n_clicks)

self.startServer(
app,
debug=True,
use_reloader=False,
use_debugger=True,
dev_tools_hot_reload=False,
)

self.wait_for_element_by_css_selector('#python').click()
self.wait_for_element_by_css_selector('#python').click()
self.wait_for_element_by_css_selector('#python').click()
self.wait_for_text_to_equal('#output', 'button clicks: 3')

# two exceptions fired, but only a single exception appeared in the UI:
# the prevent default was not displayed
self.wait_for_text_to_equal('.test-devtools-error-count', '1')
self.percy_snapshot('devtools - prevent update - only a single exception')

def test_devtools_validation_errors_in_place(self):
app = dash.Dash(__name__)
Expand Down Expand Up @@ -2921,4 +2959,4 @@ def display_content(pathname):
'devtools validation no exception: {}'.format(
test_cases[test_case_id]['name']
)
)
)