Handle catching unknowns

This commit is contained in:
Misode
2021-09-09 22:34:22 +02:00
parent fd503f1d03
commit e3fb5923c0
4 changed files with 20 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ import { locale } from '../Locales'
import { transformOutput } from '../schema/transformOutput'
import type { BlockStateRegistry } from '../Schemas'
import { Store } from '../Store'
import { message } from '../Utils'
const INDENT: Record<string, number | string> = {
'2_spaces': 2,
@@ -39,7 +40,7 @@ export function SourcePanel({ lang, name, model, blockStates, doCopy, doDownload
const data = model.schema.hook(transformOutput, new ModelPath(model), model.data, props)
source.current.value = JSON.stringify(data, null, INDENT[indent]) + '\n'
} catch (e) {
onError(`Error getting JSON output: ${e.message}`)
onError(`Error getting JSON output: ${message(e)}`)
console.error(e)
source.current.value = ''
}
@@ -62,7 +63,7 @@ export function SourcePanel({ lang, name, model, blockStates, doCopy, doDownload
const data = JSON.parse(source.current.value)
model?.reset(data, false)
} catch (e) {
onError(`Error importing: ${e.message}`)
onError(`Error importing: ${message(e)}`)
}
}