Skip to content

Commit

Permalink
Revert "inline errors sometimes"
Browse files Browse the repository at this point in the history
This reverts commit 867fd4e.
  • Loading branch information
felixroos committed Jan 16, 2025
1 parent 867fd4e commit c391305
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 178 deletions.
3 changes: 1 addition & 2 deletions kabelsalat.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<body>
<script type="module">
import { SalatRepl } from '@kabelsalat/web';
import { ErrorMessage } from './src/error';
const kabelsalat = new SalatRepl();
function send(type, msg) {
window.parent.postMessage({ type, msg });
Expand Down Expand Up @@ -95,7 +94,7 @@
window.parent.strudel.setDocPattern(docId, docPattern);
}
} catch (err) {
send('onError', new ErrorMessage(0, `${err}`), docId);
send('onError', [`kabelsalat error: ${err.message}`, docId]);
}
}
});
Expand Down
23 changes: 0 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 0 additions & 113 deletions src/error.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/hydra.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Hydra from 'hydra-synth';
import { ErrorMessage } from './error';

export class HydraSession {
constructor({ onError, canvas, onHighlight }) {
Expand Down Expand Up @@ -121,7 +120,7 @@ export class HydraSession {
})()`);
} catch (error) {
console.error(error);
this.onError(new ErrorMessage(0, error.message), docId);
this.onError(`${error}`, docId);
}
}
}
14 changes: 11 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { nudelConfirm } from './confirm.js';
import { applySettingsToNudel } from './settings.js';
import { PastaMirror } from './editor.js';
import './style.css';
import { displayEditorError, clearEditorErrors, ErrorMessage } from './error.js';

export const pastamirror = new PastaMirror();
window.editorViews = pastamirror.editorViews;
Expand Down Expand Up @@ -75,11 +74,20 @@ const setError = (message, docId) => {
// todo: where to show global errors?
return;
}
const slot = document.querySelector(`#slot-${docId}`);
let errorEl = document.querySelector(`#slot-${docId} #error-${docId}`);

displayEditorError(docId, message);
if (errorEl) {
errorEl.innerText = message;
} else {
slot.insertAdjacentHTML('beforeend', `<div class="error" id="error-${docId}">${message}</div>`);
}
};
const clearError = (docId) => {
document.querySelector(`#slot-${docId} #error-${docId}`)?.remove();
};
// clear local error when new eval comes in
session.on('eval', (msg) => clearEditorErrors(msg.docId));
session.on('eval', (msg) => clearError(msg.docId));

window.addEventListener('message', (event) => {
if (event.origin !== window.location.origin) {
Expand Down
13 changes: 1 addition & 12 deletions src/shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Copyright (C) 2025 nudel contributors
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import { ErrorMessage } from './error';

// The standard fullscreen vertex shader.
const vertexShader = `#version 300 es
precision highp float;
Expand Down Expand Up @@ -271,14 +268,6 @@ function reloadShaderInstanceCode(instance, code) {
instance.update();
}

const errorRegex = /ERROR:\s+\d+:(\d+):\s+(.+)/g;
function parseError(text) {
console.log(text);
const m = errorRegex.exec(text);
const linesInTemplateBeforeUserText = 8;
return new ErrorMessage(parseInt(m[1]) - linesInTemplateBeforeUserText, m[2]);
}

export class ShaderSession {
constructor({ onError, canvas }) {
this.onError = onError;
Expand Down Expand Up @@ -306,7 +295,7 @@ export class ShaderSession {
}
console.log('Shader updated!');
} catch (err) {
this.onError(parseError(err), msg.docId);
this.onError(`${err}`, msg.docId);
}
}
}
14 changes: 1 addition & 13 deletions src/strudel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import { Framer } from '@strudel/draw';
import { registerSoundfonts } from '@strudel/soundfonts';
import { transpiler } from '@strudel/transpiler';
import { getAudioContext, initAudio, registerSynthSounds, samples, webaudioOutput } from '@strudel/webaudio';
import { ErrorMessage } from './error';

const errorRegex = /^\s*(.+)\s*\((\d+):\d+\)\s*/g;

function parseError(text) {
try {
const matches = errorRegex.exec(text);
return new ErrorMessage(parseInt(matches[2]), matches[1]);
} catch {
return new ErrorMessage(0, text);
}
}

controls.createParam('docId');

Expand Down Expand Up @@ -223,7 +211,7 @@ export class StrudelSession {
//console.log("afterEval", meta);
} catch (err) {
console.error(err);
this.onError(parseError(err), docId);
this.onError(`${err}`, docId);
}
}
}
14 changes: 4 additions & 10 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,12 @@ body {
.error {
background-color: black;
font-family: monospace;
padding: 8px;
margin: 0;
color: tomato;
padding: 0px 2px;
border-radius: 3px;
}

.error-inline {
border-top: 2px dotted tomato;
}

.error-file {
border: 2px solid white;
color: tomato;
position: sticky;
bottom: 0;
}
}

Expand Down

0 comments on commit c391305

Please sign in to comment.