Skip to content

Commit

Permalink
Update onError callback default (visgl#5702)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored May 5, 2021
1 parent d7f89f5 commit 763f62f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
6 changes: 4 additions & 2 deletions docs/api-reference/core/deck.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,14 @@ Receives arguments:
##### `onError` (Function)
Called if deck.gl encounters an error. By default, deck logs the error to console and attempt to continue rendering the rest of the scene.
* Default: `console.error`
Called if deck.gl encounters an error. By default, deck logs the error to console and attempt to continue rendering the rest of the scene. If this callback is set to `null`, errors are silently ignored.
Receives arguments:
* `error` ([Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error))
* `source` - the source of the error, likely a Layer instance
* `layer` (Layer?) - the layer where the error is originated, if applicable
##### `_onMetrics` (Function)
Expand Down
4 changes: 4 additions & 0 deletions docs/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ The module entry point is now only lightly transpiled for the most commonly used
- `GeoJsonLayer`'s `lineJointRounded` prop now only controls line joints. To use rounded line caps, set `lineCapRounded` to `true`.
- Dashed lines via `PathStyleExtension` now draw rounded dash caps if `capRounded` is `true`.

### onError Callback

`Deck`'s default `onError` callback is changed to `console.error`. Explicitly setting `onError` to `null` now silently ignores all errors, instead of logging them to console.

## Upgrading from deck.gl v8.3 to v8.4

### wrapLongitude
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const defaultProps = {
onBeforeRender: noop,
onAfterRender: noop,
onLoad: noop,
onError: null,
onError: (error, layer) => log.error(error)(),
_onMetrics: null,

getCursor,
Expand Down
7 changes: 2 additions & 5 deletions modules/core/src/lib/layer-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,8 @@ export default class LayerManager {
}

_handleError(stage, error, layer) {
if (this._onError) {
this._onError(error, layer);
} else {
log.error(`error during ${stage} of ${layerName(layer)}`, error)();
}
error.message = `${stage} of ${layerName(layer)}: ${error.message}`;
this._onError?.(error, layer);
}

// Match all layers, checking for caught errors
Expand Down
16 changes: 5 additions & 11 deletions modules/core/src/passes/layers-pass.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import GL from '@luma.gl/constants';
import Pass from './pass';
import {clear, setParameters, withParameters, cssToDeviceRatio} from '@luma.gl/core';
import log from '../utils/log';

export default class LayersPass extends Pass {
render(props) {
Expand All @@ -15,6 +14,7 @@ export default class LayersPass extends Pass {
// Draw a list of layers in a list of viewports
_drawLayers(props) {
const {viewports, views, onViewportActive, clearCanvas = true} = props;
props.pass = props.pass || 'unknown';

const gl = this.gl;
if (clearCanvas) {
Expand Down Expand Up @@ -50,10 +50,7 @@ export default class LayersPass extends Pass {
// Resolve the parameters needed to draw each layer
// When a viewport contains multiple subviewports (e.g. repeated web mercator map),
// this is only done once for the parent viewport
_getDrawLayerParams(
viewport,
{layers, pass = 'unknown', layerFilter, effects, moduleParameters}
) {
_getDrawLayerParams(viewport, {layers, pass, layerFilter, effects, moduleParameters}) {
const drawLayerParams = [];
const indexResolver = layerIndexResolver();
for (let layerIndex = 0; layerIndex < layers.length; layerIndex++) {
Expand Down Expand Up @@ -89,7 +86,7 @@ export default class LayersPass extends Pass {
// TODO - when picking we could completely skip rendering viewports that dont
// intersect with the picking rect
/* eslint-disable max-depth, max-statements */
_drawLayersInViewport(gl, {layers, onError, viewport, view}, drawLayerParams) {
_drawLayersInViewport(gl, {layers, pass, onError, viewport, view}, drawLayerParams) {
const glViewport = getGLViewport(gl, {viewport});

if (view && view.props.clear) {
Expand Down Expand Up @@ -144,11 +141,8 @@ export default class LayersPass extends Pass {
parameters: layerParameters
});
} catch (err) {
if (onError) {
onError(err, layer);
} else {
log.error(`error during drawing of ${layer}`, err)();
}
err.message = `drawing ${layer} to ${pass}: ${err.message}`;
onError?.(err, layer);
}
}
}
Expand Down

0 comments on commit 763f62f

Please sign in to comment.