forked from MapComplete/MapComplete
Improve script to handle errors
This commit is contained in:
parent
d28acfdb20
commit
3079bbb934
2 changed files with 101 additions and 69 deletions
|
@ -1,5 +1,5 @@
|
||||||
import Script from "./Script"
|
import Script from "./Script"
|
||||||
import { readFileSync, writeFileSync } from "fs"
|
import { appendFileSync, readFileSync, writeFile, writeFileSync } from "fs"
|
||||||
import { ChangeDescription } from "../src/Logic/Osm/Actions/ChangeDescription"
|
import { ChangeDescription } from "../src/Logic/Osm/Actions/ChangeDescription"
|
||||||
import { Changes } from "../src/Logic/Osm/Changes"
|
import { Changes } from "../src/Logic/Osm/Changes"
|
||||||
import { OsmObject } from "../src/Logic/Osm/OsmObject"
|
import { OsmObject } from "../src/Logic/Osm/OsmObject"
|
||||||
|
@ -28,57 +28,15 @@ 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")
|
||||||
}
|
}
|
||||||
async main(args: string[]): Promise<void> {
|
|
||||||
const osmConnection = new OsmConnection()
|
|
||||||
const downloader = new OsmObjectDownloader(osmConnection.Backend(), undefined)
|
|
||||||
|
|
||||||
const path = args[0]
|
private readonly ignoreUsers = new Set<string>([])
|
||||||
const lines = readFileSync(path, "utf8").split("\n")
|
|
||||||
|
|
||||||
const createdChangesets = new Set<string>()
|
private async handleError(parsed: ErrorMessage, changesObj: Changes, downloader: OsmObjectDownloader, createdChangesets: Set<string>, refusedFiles: Set<string>) {
|
||||||
const refusedFiles: Set<string> = new Set<string>()
|
|
||||||
refusedFiles.add("[]")
|
|
||||||
|
|
||||||
const changesObj = new Changes(
|
|
||||||
{
|
|
||||||
dryRun: new ImmutableStore(true),
|
|
||||||
osmConnection,
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
(err) => console.error(err)
|
|
||||||
)
|
|
||||||
|
|
||||||
const all: ErrorMessage[] = []
|
|
||||||
for (const line of lines) {
|
|
||||||
if (!line?.trim()) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const parsed: ErrorMessage = JSON.parse(line)
|
|
||||||
const e = parsed.message
|
|
||||||
if (e.layout === "grb") {
|
|
||||||
console.log("Skipping GRB ")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for (const pendingChange of e.pendingChanges) {
|
|
||||||
console.log(
|
|
||||||
"\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id,
|
|
||||||
pendingChange.meta.changeType,
|
|
||||||
pendingChange.doDelete ? "DELETE" : ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
all.push(parsed)
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Parsing line failed:", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const parsed of all) {
|
|
||||||
console.log(
|
console.log(
|
||||||
parsed.message.username,
|
parsed.message.username,
|
||||||
parsed.message.layout,
|
parsed.message.layout,
|
||||||
parsed.message.message,
|
parsed.message.message,
|
||||||
parsed.date
|
parsed.date,
|
||||||
)
|
)
|
||||||
|
|
||||||
const e = parsed.message
|
const e = parsed.message
|
||||||
|
@ -88,10 +46,22 @@ class HandleErrors extends Script {
|
||||||
id: string
|
id: string
|
||||||
osmObj: OsmObject | "deleted"
|
osmObj: OsmObject | "deleted"
|
||||||
}>(
|
}>(
|
||||||
neededIds.map(async (id) => ({
|
neededIds.map(async (id) => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
const osmObj = await downloader.DownloadObjectAsync(id)
|
||||||
|
return ({
|
||||||
id,
|
id,
|
||||||
osmObj: await downloader.DownloadObjectAsync(id),
|
osmObj,
|
||||||
}))
|
})
|
||||||
|
} catch (e) {
|
||||||
|
console.error("COULD NOT DOWNLOAD OBJECT", id)
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
osmObj: "deleted",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
const objects = osmObjects
|
const objects = osmObjects
|
||||||
|
@ -104,7 +74,7 @@ class HandleErrors extends Script {
|
||||||
newObjects: OsmObject[]
|
newObjects: OsmObject[]
|
||||||
modifiedObjects: OsmObject[]
|
modifiedObjects: OsmObject[]
|
||||||
deletedObjects: OsmObject[]
|
deletedObjects: OsmObject[]
|
||||||
} = changesObj.CreateChangesetObjects(toUpload, objects)
|
} = changesObj.CreateChangesetObjects(toUpload, objects, true)
|
||||||
|
|
||||||
const changeset = Changes.createChangesetFor("", changes)
|
const changeset = Changes.createChangesetFor("", changes)
|
||||||
const path =
|
const path =
|
||||||
|
@ -142,6 +112,64 @@ ${changeset}`
|
||||||
console.log("Written refused", path)
|
console.log("Written refused", path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async main(args: string[]): Promise<void> {
|
||||||
|
const osmConnection = new OsmConnection()
|
||||||
|
const downloader = new OsmObjectDownloader(osmConnection.Backend(), undefined)
|
||||||
|
|
||||||
|
const path = args[0]
|
||||||
|
const lines = readFileSync(path, "utf8").split("\n")
|
||||||
|
|
||||||
|
const createdChangesets = new Set<string>()
|
||||||
|
const refusedFiles: Set<string> = new Set<string>()
|
||||||
|
refusedFiles.add("[]")
|
||||||
|
|
||||||
|
const changesObj = new Changes(
|
||||||
|
{
|
||||||
|
dryRun: new ImmutableStore(true),
|
||||||
|
osmConnection,
|
||||||
|
},
|
||||||
|
false,
|
||||||
|
(err) => console.error(err),
|
||||||
|
)
|
||||||
|
|
||||||
|
const all: ErrorMessage[] = []
|
||||||
|
for (const line of lines) {
|
||||||
|
if (!line?.trim()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const parsed: ErrorMessage = JSON.parse(line)
|
||||||
|
const e = parsed.message
|
||||||
|
if (e.layout === "grb") {
|
||||||
|
console.log("Skipping GRB ")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (this.ignoreUsers.has(e.username)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for (const pendingChange of e.pendingChanges) {
|
||||||
|
console.log(
|
||||||
|
"\t https://osm.org/" + pendingChange.type + "/" + pendingChange.id,
|
||||||
|
pendingChange.meta.changeType,
|
||||||
|
pendingChange.doDelete ? "DELETE" : "",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
all.push(parsed)
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Parsing line failed:", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const parsed of all) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
await this.handleError(parsed, changesObj, downloader, createdChangesets, refusedFiles)
|
||||||
|
} catch (e) {
|
||||||
|
console.error("ERROR: could not handle ", parsed, " due to", e)
|
||||||
|
writeFileSync("ERRORS."+parsed.index, "ERROR: due to " + e + ": could not handle\n" + JSON.stringify(parsed), "utf8")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,8 @@ export class Changes {
|
||||||
|
|
||||||
public CreateChangesetObjects(
|
public CreateChangesetObjects(
|
||||||
changes: ChangeDescription[],
|
changes: ChangeDescription[],
|
||||||
downloadedOsmObjects: OsmObject[]
|
downloadedOsmObjects: OsmObject[],
|
||||||
|
ignoreNoCreate: boolean = false
|
||||||
): {
|
): {
|
||||||
newObjects: OsmObject[]
|
newObjects: OsmObject[]
|
||||||
modifiedObjects: OsmObject[]
|
modifiedObjects: OsmObject[]
|
||||||
|
@ -314,6 +315,9 @@ export class Changes {
|
||||||
}
|
}
|
||||||
if (change.changes === undefined) {
|
if (change.changes === undefined) {
|
||||||
// This object is a change to a newly created object. However, we have not seen the creation changedescription yet!
|
// This object is a change to a newly created object. However, we have not seen the creation changedescription yet!
|
||||||
|
if(ignoreNoCreate){
|
||||||
|
continue
|
||||||
|
}
|
||||||
throw "Not a creation of the object: " + JSON.stringify(change)
|
throw "Not a creation of the object: " + JSON.stringify(change)
|
||||||
}
|
}
|
||||||
// This is a new object that should be created
|
// This is a new object that should be created
|
||||||
|
|
Loading…
Reference in a new issue