Skip to content

Commit

Permalink
Add sanity limits for the error box
Browse files Browse the repository at this point in the history
ref #763
  • Loading branch information
frostburn committed Jul 13, 2024
1 parent efeb324 commit d8db61b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/components/ScaleControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,10 @@ defineExpose({ focus, clearPaletteInfo })
background: none;
color: var(--color-text-mute);
}
p.error,
p.warning {
max-height: 12em;
overflow-y: auto;
}
</style>
8 changes: 5 additions & 3 deletions src/stores/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import { midiKeyInfo } from 'xen-midi'
import { undoHistory } from '@/undo'
import { useHarmonicEntropyStore } from './harmonic-entropy'

const MAX_ERROR_LENGTH = 10000

// Colors from #1 to #12 inclusive.
function defaultColors(base: number) {
return [...Array(12).keys()].map((i) => MIDI_NOTE_COLORS[mmod(base + 1 + i, 12)])
Expand Down Expand Up @@ -345,7 +347,7 @@ export const useScaleStore = defineStore('scale', () => {
function warn(this: ExpressionVisitor, ...args: any[]) {
const s = repr.bind(this)
const message = args.map((a) => (typeof a === 'string' ? a : s(a))).join(', ')
warning.value = message
warning.value = message.slice(0, MAX_ERROR_LENGTH)
}
warn.__doc__ = 'Issue a warning to the user and continue execution.'
warn.__node__ = builtinNode(warn)
Expand Down Expand Up @@ -530,9 +532,9 @@ export const useScaleStore = defineStore('scale', () => {
}
} catch (e) {
if (e instanceof Error) {
error.value = e.message
error.value = e.message.slice(0, MAX_ERROR_LENGTH)
} else if (typeof e === 'string') {
error.value = e
error.value = e.slice(0, MAX_ERROR_LENGTH)
}
}
}
Expand Down

0 comments on commit d8db61b

Please sign in to comment.