-
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
4cf9585
commit a4dff1f
Showing
2 changed files
with
54 additions
and
3 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,30 @@ | ||
import * as widgets from '@jupyter-widgets/base'; | ||
|
||
// Create a Widget Model that captures an error object | ||
export function createErrorWidget(error: string) : any { | ||
class ErrorWidget extends widgets.DOMWidgetModel { | ||
constructor(attributes?: any, options?: any) { | ||
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); | ||
} | ||
} | ||
return ErrorWidget as any; | ||
} | ||
|
||
export class ErrorWidgetView extends widgets.DOMWidgetView { | ||
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