Improve handle-error script

This commit is contained in:
Pieter Vander Vennet 2024-08-01 16:00:31 +02:00
parent 913c17a76e
commit 6031e00e99

View file

@ -8,11 +8,31 @@ import { OsmConnection } from "../src/Logic/Osm/OsmConnection"
import { ImmutableStore } from "../src/Logic/UIEventSource" import { ImmutableStore } from "../src/Logic/UIEventSource"
import { Utils } from "../src/Utils" import { Utils } from "../src/Utils"
type ErrorMessage = {
ip: string
index: number
date: string
message: {
stacktrace: string
message: string
layout: string
version: string
language: string
username: string
userid: number
pendingChanges: ChangeDescription[]
}
}
class HandleErrors extends Script { class HandleErrors extends Script {
constructor() { constructor() {
super("Inspects the errors made on a given day. Argument: path to errors") super("Inspects the errors made on a given day. Argument: path to errors")
} }
parseLine() {
}
async main(args: string[]): Promise<void> { async main(args: string[]): Promise<void> {
const osmConnection = new OsmConnection() const osmConnection = new OsmConnection()
const downloader = new OsmObjectDownloader(osmConnection.Backend(), undefined) const downloader = new OsmObjectDownloader(osmConnection.Backend(), undefined)
@ -29,26 +49,13 @@ class HandleErrors extends Script {
osmConnection, osmConnection,
}, false, err => console.error(err)) }, false, err => console.error(err))
const all: ErrorMessage[] = []
for (const line of lines) { for (const line of lines) {
if (!line?.trim()) { if (!line?.trim()) {
continue continue
} }
try { try {
const parsed: { const parsed: ErrorMessage = JSON.parse(line)
ip: string
index: number
date: string
message: {
stacktrace: string
message: string
layout: string
version: string
language: string
username: string
userid: number
pendingChanges: ChangeDescription[]
}
} = JSON.parse(line)
const e = parsed.message const e = parsed.message
if (e.layout === "grb") { if (e.layout === "grb") {
console.log("Skipping GRB ") console.log("Skipping GRB ")
@ -59,10 +66,18 @@ class HandleErrors extends Script {
console.log( console.log(
"\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id, "\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id,
pendingChange.meta.changeType, pendingChange.meta.changeType,
pendingChange.doDelete ? "DELETE" : "" pendingChange.doDelete ? "DELETE" : "",
) )
} }
all.push(parsed)
} catch (e) {
console.log("Parsing line failed:", e)
}
}
for (const parsed of all) {
const e = parsed.message
const neededIds = Changes.GetNeededIds(e.pendingChanges) const neededIds = Changes.GetNeededIds(e.pendingChanges)
// We _do not_ pass in the Changes object itself - we want the data from OSM directly in order to apply the changes // We _do not_ pass in the Changes object itself - we want the data from OSM directly in order to apply the changes
const osmObjects: { id: string; osmObj: OsmObject | "deleted" }[] = const osmObjects: { id: string; osmObj: OsmObject | "deleted" }[] =
@ -73,7 +88,7 @@ class HandleErrors extends Script {
neededIds.map(async (id) => ({ neededIds.map(async (id) => ({
id, id,
osmObj: await downloader.DownloadObjectAsync(id), osmObj: await downloader.DownloadObjectAsync(id),
})) })),
) )
const objects = osmObjects const objects = osmObjects
@ -101,13 +116,13 @@ class HandleErrors extends Script {
console.log( console.log(
"Changes for " + "Changes for " +
parsed.index + parsed.index +
": empty changeset, not creating a file for it" ": empty changeset, not creating a file for it",
) )
} else if (createdChangesets.has(changeset)) { } else if (createdChangesets.has(changeset)) {
console.log( console.log(
"Changeset " + "Changeset " +
parsed.index + parsed.index +
" is identical to previously seen changeset, not writing to file" " is identical to previously seen changeset, not writing to file",
) )
} else { } else {
writeFileSync(path, changeset, "utf8") writeFileSync(path, changeset, "utf8")
@ -118,18 +133,20 @@ class HandleErrors extends Script {
console.log( console.log(
"Refused changes for " + "Refused changes for " +
parsed.index + parsed.index +
" is identical to previously seen changeset, not writing to file" " is identical to previously seen changeset, not writing to file",
) )
} else { } else {
writeFileSync(path + ".refused.json", refusedContent, "utf8") writeFileSync(path + ".refused.json", refusedContent, "utf8")
refusedFiles.add(refusedContent) refusedFiles.add(refusedContent)
} }
console.log("Written", path, "with " + e.pendingChanges.length + " changes") console.log("Written", path, "with " + e.pendingChanges.length + " changes")
} catch (e) {
console.log("Parsing line failed:", e)
}
} }
} }
} }
new HandleErrors().run() new
HandleErrors()
.run()