-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: when a widget fails, show a fallback error widget
- Loading branch information
1 parent
bfa0e8b
commit 85fd9d9
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import * as widgets from "@jupyter-widgets/base"; | ||
|
||
// create a Widget Model that captures an error object | ||
export | ||
function createErrorWidget(error) { | ||
class ErrorWidget extends widgets.DOMWidgetModel { | ||
constructor(attributes, options) { | ||
attributes = {...attributes, | ||
_view_name: 'ErrorWidgetView', | ||
_view_module: 'voila-errorwidget', | ||
_model_module_version: '1.0.0', | ||
_view_module_version: '1.0.0', | ||
failed_module: attributes._view_module, | ||
failed_model_name: attributes._model_name, | ||
error: error} | ||
super(attributes, options); | ||
console.log(attributes); | ||
} | ||
} | ||
return ErrorWidget; | ||
} | ||
|
||
export | ||
class ErrorWidgetView extends widgets.DOMWidgetView { | ||
render() { | ||
console.log('render'); | ||
const module = this.model.get('failed_module'); | ||
const name = this.model.get('failed_model_name'); | ||
const error = String(this.model.get('error').stack); | ||
this.el.innerHTML = `Failed to load widget '${name}' from module '${module}', error:<pre>${error}</pre>`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters