diff --git a/src/Logic/Osm/Changes.ts b/src/Logic/Osm/Changes.ts index ed2b8c1f4..a547b0f52 100644 --- a/src/Logic/Osm/Changes.ts +++ b/src/Logic/Osm/Changes.ts @@ -54,7 +54,7 @@ export class Changes { featureSwitchIsTesting?: Store } osmConnection: OsmConnection - reportError?: (error: string) => void + reportError?: ((message: string | Error | XMLHttpRequest, extramessage?: string) => void), featureProperties?: FeaturePropertiesStore historicalUserLocations?: FeatureSource> allElements?: IndexedFeatureSource @@ -75,7 +75,7 @@ export class Changes { } this.state = state this.backend = state.osmConnection.Backend() - this._reportError = state.reportError + this._reportError = (msg, err) => state.reportError(msg, err) this._changesetHandler = new ChangesetHandler( state.featureSwitches?.featureSwitchIsTesting ?? new ImmutableStore(false), state.osmConnection, @@ -669,19 +669,24 @@ export class Changes { const createdIds = new Set( pending.filter((cd) => cd.changes !== undefined).map((cd) => cd.id) ) - pending.forEach((c) => { - if (c.id < 0) { - if (createdIds.has(c.id)) { + for (const c of pending) { + let id = c.id + const newId = this._changesetHandler._remappings.get(c.type + "/" + c.id) + if (newId) { + id = Number(newId.split("/")[1]) + } + if (id < 0) { + if (createdIds.has(id)) { toUpload.push(c) } else { this._reportError( - `Got an orphaned change. The 'creation'-change description for ${c.type}/${c.id} got lost. Permanently dropping this change:` + + `Got an orphaned change. The 'creation'-change description for ${c.type}/${id} got lost. Permanently dropping this change:` + JSON.stringify(c) ) } - return + continue } - const matchFound = !!objects.find((o) => o.id === c.id && o.type === c.type) + const matchFound = !!objects.find((o) => o.id === id && o.type === c.type) if (matchFound) { toUpload.push(c) } else { @@ -689,12 +694,12 @@ export class Changes { "Refusing change about " + c.type + "/" + - c.id + + id + " as not in the objects. No internet?" ) refused.push(c) } - }) + } return { refused, toUpload } } diff --git a/src/Logic/Osm/ChangesetHandler.ts b/src/Logic/Osm/ChangesetHandler.ts index 7e8a2fb7a..72c3df885 100644 --- a/src/Logic/Osm/ChangesetHandler.ts +++ b/src/Logic/Osm/ChangesetHandler.ts @@ -40,7 +40,8 @@ export class ChangesetHandler { private readonly backend: string /** - * Contains previously rewritten IDs + * Contains previously rewritten IDs, e.g. {"node/-1" --> "node/123456"} + * * @private */ public readonly _remappings = new Map() diff --git a/src/Models/ThemeViewState/WithChangesState.ts b/src/Models/ThemeViewState/WithChangesState.ts index 0f5499b72..27640295d 100644 --- a/src/Models/ThemeViewState/WithChangesState.ts +++ b/src/Models/ThemeViewState/WithChangesState.ts @@ -1,5 +1,7 @@ import { Changes } from "../../Logic/Osm/Changes" -import { NewGeometryFromChangesFeatureSource } from "../../Logic/FeatureSource/Sources/NewGeometryFromChangesFeatureSource" +import { + NewGeometryFromChangesFeatureSource +} from "../../Logic/FeatureSource/Sources/NewGeometryFromChangesFeatureSource" import { WithLayoutSourceState } from "./WithLayoutSourceState" import ThemeConfig from "../ThemeConfig/ThemeConfig" import { Utils } from "../../Utils" @@ -18,9 +20,7 @@ import { Map as MlMap } from "maplibre-gl" import FilteringFeatureSource from "../../Logic/FeatureSource/Sources/FilteringFeatureSource" import ShowDataLayer from "../../UI/Map/ShowDataLayer" import SelectedElementTagsUpdater from "../../Logic/Actors/SelectedElementTagsUpdater" -import NoElementsInViewDetector, { - FeatureViewState, -} from "../../Logic/Actors/NoElementsInViewDetector" +import NoElementsInViewDetector, { FeatureViewState } from "../../Logic/Actors/NoElementsInViewDetector" export class WithChangesState extends WithLayoutSourceState { readonly changes: Changes @@ -43,7 +43,7 @@ export class WithChangesState extends WithLayoutSourceState { osmConnection: this.osmConnection, featureProperties: this.featureProperties, historicalUserLocations: this.historicalUserLocations, - reportError: this.reportError, + reportError: (err, msg) => this.reportError(err, msg) }, theme?.isLeftRightSensitive() ?? false ) @@ -104,16 +104,6 @@ export class WithChangesState extends WithLayoutSourceState { return } const isTesting = this.featureSwitchIsTesting?.data - console.log( - isTesting - ? ">>> _Not_ reporting error to report server as testmode is on" - : ">>> Reporting error to", - Constants.ErrorReportServer, - message - ) - if (isTesting) { - return - } if ("" + message === "[object XMLHttpRequest]") { const req = message @@ -137,25 +127,35 @@ export class WithChangesState extends WithLayoutSourceState { } const stacktrace: string = new Error().stack - try { + const err = { + stacktrace, + message: "" + message, + theme: this.theme?.id, + version: Constants.vNumber, + language: this.userRelatedState.language.data, + username: this.osmConnection.userDetails.data?.name, + userid: this.osmConnection.userDetails.data?.uid, + pendingChanges: this.changes.pendingChanges.data, + previousChanges: this.changes.allChanges.data, + changeRewrites: Utils.MapToObj(this.changes._changesetHandler._remappings) + } + console.trace( + isTesting + ? ">>> _Not_ reporting error to report server as testmode is on" + : ">>> Reporting error to", + Constants.ErrorReportServer, + message, err + ) + if (isTesting) { + return + } await fetch(Constants.ErrorReportServer, { method: "POST", - body: JSON.stringify({ - stacktrace, - message: "" + message, - theme: this.theme.id, - version: Constants.vNumber, - language: this.userRelatedState.language.data, - username: this.osmConnection.userDetails.data?.name, - userid: this.osmConnection.userDetails.data?.uid, - pendingChanges: this.changes.pendingChanges.data, - previousChanges: this.changes.allChanges.data, - changeRewrites: Utils.MapToObj(this.changes._changesetHandler._remappings), - }), + body: JSON.stringify(err) }) } catch (e) { - console.error("Could not upload an error report") + console.error("Could not upload an error report", e) } } diff --git a/src/Models/ThemeViewState/WithImageState.ts b/src/Models/ThemeViewState/WithImageState.ts index da1d564eb..79a55aa8b 100644 --- a/src/Models/ThemeViewState/WithImageState.ts +++ b/src/Models/ThemeViewState/WithImageState.ts @@ -29,7 +29,7 @@ export class WithImageState extends WithGuiState implements SpecialVisualization this.osmConnection, this.changes, this.geolocation.geolocationState.currentGPSLocation, - this.reportError + (err, msg) => this.reportError(err, msg) ) const longAgo = new Date() longAgo.setTime(new Date().getTime() - 5 * 365 * 24 * 60 * 60 * 1000) diff --git a/src/UI/Map/ProtomapsLanguageSupport.ts b/src/UI/Map/ProtomapsLanguageSupport.ts index 7df4ab144..3f5a75b7a 100644 --- a/src/UI/Map/ProtomapsLanguageSupport.ts +++ b/src/UI/Map/ProtomapsLanguageSupport.ts @@ -3,7 +3,7 @@ import { DataDrivenPropertyValueSpecification, LayerSpecification, Map as MlMap, - SymbolLayerSpecification, + SymbolLayerSpecification } from "maplibre-gl" import Locale from "../i18n/Locale" import { Utils } from "../../Utils" @@ -1752,7 +1752,6 @@ export class ProtomapsLanguageSupport { } const newExpressionF = ProtomapsLanguageSupport.expressions[layer.id] if (!newExpressionF) { - console.log(">>> No function found for", layer.id) return } const newExpression = newExpressionF(language)