Skip to content

Commit

Permalink
feat: always display console errors; include asserts and other consol…
Browse files Browse the repository at this point in the history
…e log in debug builds only
  • Loading branch information
arnog committed Feb 16, 2023
1 parent f7a1a2b commit 0667de8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 24 deletions.
7 changes: 6 additions & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const BUILD_OPTIONS = {
SDK_VERSION: JSON.stringify(SDK_VERSION),
GIT_VERSION: JSON.stringify(process.env.GIT_VERSION || '?.?.?'),
},
drop: ['debugger', 'console'],
plugins: [less({ compress: true })],
loader: { '.ts': 'ts' },
sourcemap: !PRODUCTION,
Expand Down Expand Up @@ -50,6 +49,8 @@ build({

build({
...BUILD_OPTIONS,
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
entryPoints: ['./src/mathlive.ts'],
outfile: './dist/mathlive.min.mjs',
format: 'esm',
Expand All @@ -59,6 +60,8 @@ build({
build({
...BUILD_OPTIONS,
entryPoints: ['./src/mathlive.ts'],
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
outfile: './dist/mathlive.min.js',
format: 'iife',
globalName: 'MathLive',
Expand All @@ -68,6 +71,8 @@ build({
build({
...BUILD_OPTIONS,
entryPoints: ['./src/public/mathlive-ssr.ts'],
drop: ['debugger'],
pure: ['console.assert', 'console.log'],
outfile: './dist/mathlive-ssr.min.mjs',
format: 'esm',
minify: true,
Expand Down
5 changes: 4 additions & 1 deletion src/addons/auto-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ function createMathMLNode(
'</math>';
span.innerHTML = options.createHTML ? options.createHTML(html) : html;
} catch (error: unknown) {
console.error("Could not convert '" + latex + "' to MathML with ", error);
console.error(
"MathLive: Could not convert '" + latex + "' to MathML with ",
error
);
span.textContent = latex;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function loadFonts(fontsDirectory?: string): Promise<void> {
loadedFonts.forEach((font) => document.fonts.add(font));
} catch (error: unknown) {
console.error(
`The mathlive fonts could not be loaded from "${fontsFolder}"`,
`The MathLive fonts could not be loaded from "${fontsFolder}"`,
{ cause: error }
);
document.body.classList.add('ML__fonts-did-not-load');
Expand Down
4 changes: 2 additions & 2 deletions src/editor-mathfield/mathfield-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ export class MathfieldPrivate implements GlobalContext, Mathfield {
if (ComputeEngineCtor) this._computeEngine = new ComputeEngineCtor();
else {
console.error(
'The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
'MathLive: The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
);
}
if (this._computeEngine && this.options.decimalSeparator === ',')
Expand Down Expand Up @@ -680,7 +680,7 @@ export class MathfieldPrivate implements GlobalContext, Mathfield {

if (errors.length > 0) {
console.error(
'invalid keybindings for current keyboard layout',
'MathLive: Invalid keybindings for current keyboard layout',
errors
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/editor-model/model-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class ModelPrivate implements Model {

if (format === 'ascii-math') return atomToAsciiMath(atom);

console.warn('Unknown format :', format);
console.error('MathLive: Unknown format :', format);
return '';
}

Expand Down
18 changes: 12 additions & 6 deletions src/editor/speech-read-aloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ export function defaultReadAloudHook(
config ??= globalMathLive().config;

if (config.speechEngine !== 'amazon') {
console.warn('Use Amazon TTS Engine for synchronized highlighting');
console.error(
'MathLive: Use Amazon TTS Engine for synchronized highlighting'
);
if (config.speakHook) config.speakHook(text, config);
return;
}

if (!globalThis.AWS) {
console.warn(
'AWS SDK not loaded. See https://www.npmjs.com/package/aws-sdk'
console.error(
'MathLive: AWS SDK not loaded. See https://www.npmjs.com/package/aws-sdk'
);
return;
}
Expand All @@ -83,7 +85,11 @@ export function defaultReadAloudHook(
// Request the mark points
polly.synthesizeSpeech(parameters, (err, data) => {
if (err) {
console.warn('polly.synthesizeSpeech() error:', err, err.stack);
console.error(
'MathLive: polly.synthesizeSpeech() error:',
err,
err.stack
);
return;
}

Expand All @@ -109,8 +115,8 @@ export function defaultReadAloudHook(
parameters.SpeechMarkTypes = [];
polly.synthesizeSpeech(parameters, (err, data) => {
if (err) {
console.warn(
'polly.synthesizeSpeech(',
console.error(
'MathLive: polly.synthesizeSpeech(',
text,
') error:',
err,
Expand Down
14 changes: 9 additions & 5 deletions src/editor/speech.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export function defaultSpeakHook(
window.speechSynthesis.speak(utterance);
} else if (config.speechEngine === 'amazon') {
if (!('AWS' in window)) {
console.warn(
'AWS SDK not loaded. See https://www.npmjs.com/package/aws-sdk'
console.error(
'MathLive: AWS SDK not loaded. See https://www.npmjs.com/package/aws-sdk'
);
} else {
const polly = new globalThis.AWS.Polly({ apiVersion: '2016-06-10' });
Expand Down Expand Up @@ -225,7 +225,11 @@ export function defaultSpeakHook(
// https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Polly.html#synthesizeSpeech-property
polly.synthesizeSpeech(parameters, (err, data) => {
if (err)
console.warn('polly.synthesizeSpeech() error:', err, err.stack);
console.error(
'MathLive: polly.synthesizeSpeech() error:',
err,
err.stack
);
// Announce('plonk');
else if (data?.AudioStream) {
const uInt8Array = new Uint8Array(data.AudioStream);
Expand All @@ -242,8 +246,8 @@ export function defaultSpeakHook(
// Can call AWS.Request() on the result of synthesizeSpeech()
}
} else if (config.speechEngine === 'google') {
console.warn(
'The Google speech engine is not supported yet. Please come again.'
console.error(
'MathLive: The Google speech engine is not supported yet. Please come again.'
);
// @todo: implement support for Google Text-to-Speech API,
// using config.speechEngineToken, config.speechEngineVoice and
Expand Down
15 changes: 11 additions & 4 deletions src/editor/virtual-keyboard-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ function makeKeyboardToolbar(
};
for (const keyboard of keyboardList) {
if (!keyboards[keyboard]) {
console.error('Unknown virtual keyboard "', keyboard, '"');
console.error('MathLive: Unknown virtual keyboard "', keyboard, '"');
break;
}

Expand Down Expand Up @@ -1561,7 +1561,8 @@ function expandLayerMarkup(

let keys = layout[attributes.name] as string;
if (!keys) keys = ROWS.qwerty[attributes.name];
if (!keys) console.warn('Unknown roman keyboard row:', attributes.name);
if (!keys)
console.error('MathLive: Unknown roman keyboard row:', attributes.name);
else {
for (const c of keys) {
let cls: string = attributes.class ?? '';
Expand Down Expand Up @@ -1856,7 +1857,9 @@ export function makeKeyboardElement(
const keyboardList = keyboardIDs.replace(/\s+/g, ' ').split(' ');
for (const keyboardName of keyboardList) {
if (!keyboards[keyboardName]) {
console.error('Unknown virtual keyboard "' + keyboardName + '"');
console.error(
'MathLive: Unknown virtual keyboard "' + keyboardName + '"'
);
continue;
}

Expand All @@ -1870,7 +1873,11 @@ export function makeKeyboardElement(

for (const layerName of keyboardLayers) {
if (!layers[layerName]) {
console.error('Unknown virtual keyboard layer: "', layerName, '"');
console.error(
'MathLive: Unknown virtual keyboard layer: "',
layerName,
'"'
);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/public/mathfield-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ import 'https://unpkg.com/@cortex-js/compute-engine?module';
if (!this._mathfield) return undefined;
if (!globalThis[Symbol.for('io.cortexjs.compute-engine')]) {
console.error(
'The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
'MathLive: The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
);
}
return this._mathfield.expression;
Expand All @@ -790,7 +790,7 @@ import 'https://unpkg.com/@cortex-js/compute-engine?module';

if (!globalThis[Symbol.for('io.cortexjs.compute-engine')]) {
console.error(
'The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
'MathLive: The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/public/mathlive-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function serializeMathJsonToLatex(json: Expression): string {
if (ComputeEngineCtor) gComputeEngine = new ComputeEngineCtor();
else {
console.error(
'The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
'MathLive: The CortexJS Compute Engine library is not available.\nLoad the library, for example with:\nimport "https://unpkg.com/@cortex-js/compute-engine?module"'
);
}
}
Expand Down

0 comments on commit 0667de8

Please sign in to comment.