Skip to content

Commit

Permalink
chore: expose renderError
Browse files Browse the repository at this point in the history
  • Loading branch information
Caele committed Nov 3, 2024
1 parent ec6e6f9 commit f502db2
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 16 deletions.
6 changes: 5 additions & 1 deletion apis/nucleus/src/components/Cell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import InstanceContext from '../contexts/InstanceContext';
import useObjectSelections from '../hooks/useObjectSelections';
import eventmixin from '../selections/event-mixin';
import useStyling from '../hooks/useStyling';
import RenderError from '../utils/render-error';

/**
* @interface
Expand Down Expand Up @@ -518,7 +519,10 @@ const Cell = forwardRef(
if (state.loading && !state.longRunningQuery) {
Content = <LoadingSn />;
} else if (state.error) {
onError && onError(state.error.errorObject);
if (onError) {
const e = state.error.errorObject ? state.error.errorObject : new RenderError(state.error.title);
onError(e);
}
Content = <CError {...state.error} />;
} else if (state.loaded) {
Content = (
Expand Down
2 changes: 1 addition & 1 deletion apis/nucleus/src/object/create-session-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import init from './initiate';
* @property {HTMLElement} element Target html element to render in to
* @property {object=} options Options passed into the visualisation
* @property {function=} onRender Callback function called after rendering successfully
* @property {function=} onError Callback function called if an error occurs
* @property {function(RenderError)=} onError Callback function called if an error occurs
* @property {Plugin[]} [plugins] plugins passed into the visualisation
* @property {string=} id For existing objects: Engine identifier of object to render
* @property {string=} type For creating objects: Type of visualisation to render
Expand Down
4 changes: 2 additions & 2 deletions apis/nucleus/src/sn/load.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import VisualizationError from '../utils/visualization-error';
import RenderError from '../utils/render-error';

const LOADED = {};

Expand Down Expand Up @@ -34,7 +34,7 @@ export async function load(name, version, { config }, loader) {
if (__NEBULA_DEV__) {
console.warn(e); // eslint-disable-line no-console
}
throw new VisualizationError(`Failed to load visualization: '${sKey}'`, e);
throw new RenderError(`Failed to load visualization: '${sKey}'`, e);
});
}

Expand Down
15 changes: 15 additions & 0 deletions apis/nucleus/src/utils/render-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @class RenderError
* @extends Error
* @param {string} message
* @param {Error} originalError
* @property {Error} originalError
*/

export default class RenderError extends Error {
constructor(message, originalError) {
super(message);
this.originalError = originalError;
this.name = 'RenderError';
}
}
7 changes: 0 additions & 7 deletions apis/nucleus/src/utils/visualization-error.js

This file was deleted.

32 changes: 31 additions & 1 deletion apis/stardust/api-spec/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,11 @@
"description": "Callback function called if an error occurs",
"optional": true,
"kind": "function",
"params": []
"params": [
{
"type": "#/definitions/RenderError"
}
]
},
"plugins": {
"description": "plugins passed into the visualisation",
Expand Down Expand Up @@ -1914,6 +1918,32 @@
}
}
},
"RenderError": {
"extends": [
{
"type": "Error"
}
],
"kind": "class",
"constructor": {
"kind": "function",
"params": [
{
"name": "message",
"type": "string"
},
{
"name": "originalError",
"type": "Error"
}
]
},
"entries": {
"originalError": {
"type": "Error"
}
}
},
"Navigation": {
"stability": "experimental",
"availability": {
Expand Down
10 changes: 9 additions & 1 deletion apis/stardust/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,9 @@ declare namespace stardust {
onRender?(): void;
/**
* Callback function called if an error occurs
* @param $
*/
onError?(): void;
onError?($: stardust.RenderError): void;
plugins?: stardust.Plugin[];
id?: string;
type?: string;
Expand Down Expand Up @@ -610,6 +611,13 @@ declare namespace stardust {
meta?: object;
}

class RenderError extends Error {
constructor(message: string, originalError: Error);

originalError: Error;

}

class Navigation implements stardust.Emitter {
constructor();

Expand Down
2 changes: 1 addition & 1 deletion test/mashup/visualize/life.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="wrapper">
<div class="viz"></div>
<div class="actions"></div>
<div class="errors"></div>
<div class="errors" data-tid="error-external"></div>
</div>
</body>
</html>
4 changes: 4 additions & 0 deletions test/mashup/visualize/life.int.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ describe('object lifecycle', () => {
'[data-tid="error-title"]',
"Could not find a version of 'voooz' that supports current object version. Did you forget to register voooz?"
);
await waitForTextStatus(
'[data-tid="error-external"]',
"Could not find a version of 'voooz' that supports current object version. Did you forget to register voooz?"
);
});

it('should show spinner and requirements for known type', async () => {
Expand Down
6 changes: 4 additions & 2 deletions test/mashup/visualize/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,10 @@ async function render() {
const viz = await configuration(app).render({
element,
id: 'bb8',
onError: () => {
// const errorElement = document.querySelector('.errors');
onError: (e) => {
console.log(e);
const errorElement = document.querySelector('.errors');
errorElement.textContent = e.message;
},
});

Expand Down

0 comments on commit f502db2

Please sign in to comment.