Skip to content

Commit

Permalink
Switch consoles to log utils (#3542)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogretz2 authored Dec 1, 2023
1 parent 5a729ef commit 1c6357d
Show file tree
Hide file tree
Showing 32 changed files with 115 additions and 105 deletions.
2 changes: 1 addition & 1 deletion cmp/grid/impl/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function managedRenderer<T extends ColumnRenderer | GroupRowRenderer>(
try {
return fn.apply(null, arguments);
} catch (e) {
console.warn(`Renderer for '${identifier}' has thrown an error.`, e);
console.warn(`Renderer for '${identifier}' has thrown an error`, e);
return '#ERROR';
}
} as unknown as T;
Expand Down
7 changes: 5 additions & 2 deletions cmp/relativetimestamp/RelativeTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {fmtCompactDate, fmtDateTime} from '@xh/hoist/format';
import {action, computed, makeObservable, observable} from '@xh/hoist/mobx';
import {Timer} from '@xh/hoist/utils/async';
import {DAYS, HOURS, LocalDate, SECONDS} from '@xh/hoist/utils/datetime';
import {withDefault} from '@xh/hoist/utils/js';
import {logWarn, withDefault} from '@xh/hoist/utils/js';

interface RelativeTimestampProps extends HoistProps, BoxProps {
/**
Expand Down Expand Up @@ -231,7 +231,10 @@ function doFormat(timestamp: Date | number, opts: RelativeTimestampOptions): str

// 1) Degenerate cases
if (isFuture && !allowFuture) {
console.warn(`Unexpected future date provided for timestamp: ${elapsed}ms in the future.`);
logWarn(
`Unexpected future date provided for timestamp: ${elapsed}ms in the future.`,
RelativeTimestamp
);
return '[????]';
}

Expand Down
2 changes: 1 addition & 1 deletion cmp/zoneGrid/ZoneGridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ export class ZoneGridModel extends HoistModel {
ret[zone] = this.parseZoneMapping(zone, rawMapping);
} catch (e) {
if (strict) throw e;
console.warn(e.message);
this.logWarn(e.message);
ret[zone] = this._defaultState.mappings[zone];
}
});
Expand Down
5 changes: 3 additions & 2 deletions core/HoistBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ export abstract class HoistBase {
run: data => provider.write(data)
});
} catch (e) {
console.error(
this.logError(
`Failed to configure Persistence for '${property}'. Be sure to fully specify ` +
`'persistWith' on this object or in the method call.`
`'persistWith' on this object or in the method call`,
e
);
}
}
Expand Down
17 changes: 11 additions & 6 deletions core/HoistBaseDecorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import {cloneDeep, isUndefined} from 'lodash';
import {wait} from '../promise';
import {throwIf} from '../utils/js';
import {logError, throwIf} from '../utils/js';
import {HoistBaseClass, PersistenceProvider, PersistOptions} from './';

/**
Expand Down Expand Up @@ -66,9 +66,10 @@ function createPersistDescriptor(
'@persist decorator should be applied to an instance of HoistBase'
);
if (descriptor.get || descriptor.set) {
console.error(
logError(
`Error defining ${property} : @persist or @persistWith should be defined closest ` +
`to property, and after mobx annotation e.g. '@bindable @persist ${property}'`
`to property, and after mobx annotation e.g. '@bindable @persist ${property}'`,
target
);
return descriptor;
}
Expand All @@ -89,9 +90,13 @@ function createPersistDescriptor(
});
});
} catch (e) {
console.error(
`Failed to configure Persistence for '${property}'. Be sure to fully specify ` +
`'persistWith' on this object or annotation.`
logError(
[
`Failed to configure Persistence for '${property}'. Be sure to fully specify ` +
`'persistWith' on this object or annotation`,
e
],
target
);
}

Expand Down
4 changes: 1 addition & 3 deletions core/HoistComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ function wrapWithModel(render: RenderFn, cfg: Config): RenderFn {
if (!model && !spec.optional && spec instanceof UsesSpec) {
console.error(`
Failed to find model with selector '${formatSelector(spec.selector)}' for
component '${
cfg.displayName
}'. Ensure the proper model is available via context, or
component '${cfg.displayName}'. Ensure the proper model is available via context, or
specify explicitly using the 'model' prop.
`);
return cmpErrDisplay({...getLayoutProps(props), item: 'No model found'});
Expand Down
8 changes: 4 additions & 4 deletions core/exception/ExceptionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import {Exception} from './Exception';
import {fragment, span} from '@xh/hoist/cmp/layout';
import {stripTags} from '@xh/hoist/utils/js';
import {logError, logWarn, stripTags} from '@xh/hoist/utils/js';
import {Icon} from '@xh/hoist/icon';
import {forOwn, has, isArray, isNil, isObject, omitBy, pick, set} from 'lodash';
import {HoistException, PlainObject, XH} from '../';
Expand Down Expand Up @@ -189,7 +189,7 @@ export class ExceptionHandler {
username = XH.getUsername();

if (!username) {
console.warn('Error report cannot be submitted to UI server - user unknown');
logWarn('Error report cannot be submitted to UI server - user unknown', this);
return false;
}

Expand All @@ -206,7 +206,7 @@ export class ExceptionHandler {
});
return true;
} catch (e) {
console.error('Exception while submitting error report to UI server', e);
logError(['Exception while submitting error report to UI server', e], this);
return false;
}
}
Expand Down Expand Up @@ -261,7 +261,7 @@ export class ExceptionHandler {
return stripTags(JSON.stringify(ret, null, 4));
} catch (e) {
const message = 'Failed to serialize error';
console.error(message, exception, e);
logError([message, exception, e], this);
return JSON.stringify({message}, null, 4);
}
}
Expand Down
15 changes: 7 additions & 8 deletions core/load/LoadSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import {HoistBase, managed, PlainObject, RefreshContextModel, TaskObserver} from '../';
import {LoadSpec, Loadable} from './';
import {makeObservable, observable, runInAction} from '@xh/hoist/mobx';
import {throwIf} from '@xh/hoist/utils/js';
import {isPlainObject} from 'lodash';
import {logDebug, logError, throwIf} from '@xh/hoist/utils/js';
import {isPlainObject, pull} from 'lodash';

/**
* Provides support for objects that participate in Hoist's loading/refresh lifecycle.
Expand Down Expand Up @@ -98,18 +98,17 @@ export class LoadSupport extends HoistBase implements Loadable {
if (target instanceof RefreshContextModel) return;

const elapsed = this.lastLoadCompleted.getTime() - this.lastLoadRequested.getTime(),
msg = `[${target.constructor.name}] | ${loadSpec.typeDisplay} | ${
exception ? 'failed | ' : ''
}${elapsed}ms`;
status = exception ? 'failed' : null,
msg = pull([loadSpec.typeDisplay, status, `${elapsed}ms`, exception], null);

if (exception) {
if (exception.isRoutine) {
console.debug(msg, exception);
logDebug(msg, target);
} else {
console.error(msg, exception);
logError(msg, target);
}
} else {
console.debug(msg);
logDebug(msg, target);
}
});
}
Expand Down
12 changes: 7 additions & 5 deletions desktop/cmp/button/ColChooserButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ColChooserModel} from '@xh/hoist/desktop/cmp/grid/impl/colchooser/ColCho
import '@xh/hoist/desktop/register';
import {Icon} from '@xh/hoist/icon';
import {popover, Position} from '@xh/hoist/kit/blueprint';
import {stopPropagation, withDefault} from '@xh/hoist/utils/js';
import {logError, stopPropagation, withDefault} from '@xh/hoist/utils/js';
import {button, ButtonProps} from './Button';

export interface ColChooserButtonProps extends ButtonProps {
Expand Down Expand Up @@ -40,15 +40,17 @@ export const [ColChooserButton, colChooserButton] = hoistCmp.withFactory<ColChoo
const colChooserModel = gridModel?.colChooserModel as ColChooserModel;

if (!gridModel) {
console.error(
"No GridModel available to ColChooserButton. Provide via a 'gridModel' prop, or context."
logError(
"No GridModel available. Provide via a 'gridModel' prop, or context.",
ColChooserButton
);
disabled = true;
}

if (!colChooserModel) {
console.error(
'No ColChooserModel available on bound GridModel - enable via GridModel.colChooserModel config.'
logError(
'No ColChooserModel available on bound GridModel - enable via GridModel.colChooserModel config.',
ColChooserButton
);
disabled = true;
}
Expand Down
12 changes: 7 additions & 5 deletions desktop/cmp/button/ZoneMapperButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ZoneMapperModel} from '@xh/hoist/cmp/zoneGrid/impl/ZoneMapperModel';
import {zoneMapper} from '@xh/hoist/desktop/cmp/zoneGrid/impl/ZoneMapper';
import {Icon} from '@xh/hoist/icon';
import {popover, Position} from '@xh/hoist/kit/blueprint';
import {stopPropagation, withDefault} from '@xh/hoist/utils/js';
import {logError, stopPropagation, withDefault} from '@xh/hoist/utils/js';
import {button, ButtonProps} from './Button';

export interface ZoneMapperButtonProps extends ButtonProps {
Expand All @@ -37,15 +37,17 @@ export const [ZoneMapperButton, zoneMapperButton] = hoistCmp.withFactory<ZoneMap
const mapperModel = zoneGridModel?.mapperModel as ZoneMapperModel;

if (!zoneGridModel) {
console.error(
"No ZoneGridModel available to ZoneMapperButton. Provide via a 'zoneGridModel' prop, or context."
logError(
"No ZoneGridModel available. Provide via a 'zoneGridModel' prop, or context.",
ZoneMapperButton
);
disabled = true;
}

if (!mapperModel) {
console.error(
'No ZoneMapperModel available on bound ZoneGridModel - enable via ZoneGridModel.zoneMapperModel config.'
logError(
'No ZoneMapperModel available on bound ZoneGridModel - enable via ZoneGridModel.zoneMapperModel config.',
ZoneMapperButton
);
disabled = true;
}
Expand Down
4 changes: 2 additions & 2 deletions desktop/cmp/dash/canvas/DashCanvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class DashCanvasModel extends DashModel<
this.provider = PersistenceProvider.create({path: 'dashCanvas', ...persistWith});
persistState = this.provider.read();
} catch (e) {
console.error(e);
this.logError(e);
XH.safeDestroy(this.provider);
this.provider = null;
}
Expand Down Expand Up @@ -419,7 +419,7 @@ export class DashCanvasModel extends DashModel<
if (this.hasSpec(viewSpecId)) {
this.addViewInternal(viewSpecId, state);
} else {
console.warn(`Unknown viewSpecId [${viewSpecId}] found in state - skipping.`);
this.logWarn(`Unknown viewSpecId [${viewSpecId}] found in state - skipping.`);
}
});
} finally {
Expand Down
4 changes: 2 additions & 2 deletions desktop/cmp/dash/container/DashContainerModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class DashContainerModel extends DashModel<
this.provider = PersistenceProvider.create({path: 'dashContainer', ...persistWith});
persistState = this.provider.read();
} catch (e) {
console.error(e);
this.logError(e);
XH.safeDestroy(this.provider);
this.provider = null;
}
Expand Down Expand Up @@ -238,7 +238,7 @@ export class DashContainerModel extends DashModel<
async loadStateAsync(state) {
const containerEl = this.containerRef.current;
if (!containerEl) {
console.warn(
this.logWarn(
'DashboardContainer not yet rendered - cannot update state - change will be discarded!'
);
return;
Expand Down
4 changes: 2 additions & 2 deletions desktop/cmp/form/FormField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {fmtDate, fmtDateTime, fmtJson, fmtNumber} from '@xh/hoist/format';
import {Icon} from '@xh/hoist/icon';
import {tooltip} from '@xh/hoist/kit/blueprint';
import {isLocalDate} from '@xh/hoist/utils/datetime';
import {errorIf, getTestId, TEST_ID, throwIf, withDefault} from '@xh/hoist/utils/js';
import {errorIf, getTestId, logWarn, TEST_ID, throwIf, withDefault} from '@xh/hoist/utils/js';
import {getLayoutProps, getReactElementName, useOnMount, useOnUnmount} from '@xh/hoist/utils/react';
import classNames from 'classnames';
import {isBoolean, isDate, isEmpty, isFinite, isNil, isUndefined, kebabCase} from 'lodash';
Expand Down Expand Up @@ -107,7 +107,7 @@ export const [FormField, formField] = hoistCmp.withFactory<FormFieldProps>({
model = model ?? (formModel && field ? formModel.fields[field] : null);

if (!model) {
console.warn(`Unable to bind FormField to field "${field}" on backing FormModel`);
logWarn(`Unable to bind FormField to field "${field}" on backing FormModel`, FormField);
}

// Model related props
Expand Down
6 changes: 5 additions & 1 deletion desktop/cmp/grid/editors/BooleanEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {useImperativeHandle} from 'react';
import {EditorProps} from './EditorProps';
import './Editors.scss';
import {useInlineEditorModel} from './impl/InlineEditorModel';
import {logWarn} from '@xh/hoist/utils/js';

export interface BooleanEditorProps extends EditorProps<CheckboxProps> {
/**
Expand All @@ -35,7 +36,10 @@ export const [BooleanEditor, booleanEditor] = hoistCmp.withFactory<BooleanEditor
quickToggle = quickToggle ?? !fullRowEditing;

if (quickToggle && fullRowEditing) {
console.warn("'quickToggle' prop ignored for GridModel with full row editing.");
logWarn(
"'quickToggle' prop ignored for GridModel with full row editing.",
BooleanEditor
);
quickToggle = false;
}

Expand Down
4 changes: 1 addition & 3 deletions desktop/cmp/input/DateInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ class DateInputModel extends HoistInputModel {
if (date) {
date = this.applyPrecision(date);
} else {
console.debug(
'DateInput value exceeded max/minDate bounds on change - reset to null.'
);
this.logDebug('Value exceeded max/minDate bounds on change - reset to null.');
}
}
this.noteValueChange(date);
Expand Down
6 changes: 4 additions & 2 deletions desktop/cmp/panel/Panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {toolbar} from '@xh/hoist/desktop/cmp/toolbar';
import {useContextMenu, useHotkeys} from '@xh/hoist/desktop/hooks';
import '@xh/hoist/desktop/register';
import {HotkeyConfig} from '@xh/hoist/kit/blueprint';
import {logWarn} from '@xh/hoist/utils/js';
import {splitLayoutProps} from '@xh/hoist/utils/react';
import {castArray, omitBy} from 'lodash';
import {Children, isValidElement, ReactElement, ReactNode, useLayoutEffect, useRef} from 'react';
Expand Down Expand Up @@ -256,8 +257,9 @@ function parseLoadDecorator(prop: any, name: string, contextModel: HoistModel) {
if (prop === 'onLoad') {
const loadModel = contextModel?.loadModel;
if (!loadModel) {
console.warn(
`Cannot use 'onLoad' for '${name}' - the linked context model must enable LoadSupport to support this feature.`
logWarn(
`Cannot use 'onLoad' for '${name}' - the linked context model must enable LoadSupport to support this feature.`,
Panel
);
return null;
}
Expand Down
10 changes: 5 additions & 5 deletions desktop/cmp/panel/PanelModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,20 @@ export class PanelModel extends HoistModel {
: defaultSize;

if ((collapsible || resizable) && (isNil(defaultSize) || isNil(side))) {
console.error(
this.logError(
"Must specify 'defaultSize' and 'side' for a collapsible or resizable PanelModel. Panel sizing disabled."
);
collapsible = false;
resizable = false;
}

if (!isNil(maxSize) && maxSize < minSize) {
console.error("'maxSize' must be greater than 'minSize'. No 'maxSize' will be set.");
this.logError("'maxSize' must be greater than 'minSize'. No 'maxSize' will be set.");
maxSize = null;
}

if (resizable && !resizeWhileDragging && !showSplitter) {
console.error(
this.logError(
"Must not set 'showSplitter = false' for a resizable PanelModel unless 'resizeWhileDragging` is enabled. Panel sizing disabled."
);
resizable = false;
Expand Down Expand Up @@ -277,7 +277,7 @@ export class PanelModel extends HoistModel {
this.provider = PersistenceProvider.create({path: 'panel', ...persistWith});
state = this.provider.read() ?? this.legacyState();
} catch (e) {
console.error(e);
this.logError(e);
XH.safeDestroy(this.provider);
this.provider = null;
}
Expand Down Expand Up @@ -408,7 +408,7 @@ export class PanelModel extends HoistModel {
return data;
}
} catch (e) {
console.error('Failed reading legacy state');
this.logError('Failed reading legacy state', e);
}
}
return null;
Expand Down
Loading

0 comments on commit 1c6357d

Please sign in to comment.