Studio: improve error handling, fix renumbering

This commit is contained in:
Pieter Vander Vennet 2024-01-19 17:31:35 +01:00
parent 7afe58e6a5
commit 079a3f8694
10 changed files with 187 additions and 62 deletions

View file

@ -1,4 +1,5 @@
import { ConversionMessage, ConversionMsgLevel } from "./Conversion"
import { Context } from "maplibre-gl"
export class ConversionContext {
/**
@ -42,6 +43,31 @@ export class ConversionContext {
return new ConversionContext([], msg ? [msg] : [], ["test"])
}
/**
* Does an inline edit of the messages for which a new path is defined
* This is a slight hack
* @param rewritePath
*/
public rewriteMessages(
rewritePath: (
p: ReadonlyArray<number | string>
) => undefined | ReadonlyArray<number | string>
): void {
for (let i = 0; i < this.messages.length; i++) {
const m = this.messages[i]
const newPath = rewritePath(m.context.path)
if (!newPath) {
continue
}
const rewrittenContext = new ConversionContext(
this.messages,
newPath,
m.context.operation
)
this.messages[i] = <ConversionMessage>{ ...m, context: rewrittenContext }
}
}
static print(msg: ConversionMessage) {
const noString = msg.context.path.filter(
(p) => typeof p !== "string" && typeof p !== "number"