{"record":{"id":"f2f998a4802fc032","repo":"semaphoreui/semaphore","slug":"s-key-s-not-found","errorCode":null,"errorMessage":"%s key %s not found","messagePattern":"(.+?) key (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/export/Exporter.go","lineNumber":154,"sourceCode":"\t\t\terrHandler.onError(err.Error())\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, err\n\t}\n\n\tnewKey, err := strconv.Atoi(key)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &newKey, nil\n}\n\nfunc (d *TypeKeyMapper) getNewKey(name string, scope string, oldKey EntityKey) (EntityKey, error) {\n\tnewKey, ok := d.Keys[name][scope][oldKey]\n\tif !ok {\n\t\tmsg := fmt.Sprintf(\"%s key %s not found\", name, oldKey)\n\t\treturn \"\", errors.New(msg)\n\t}\n\n\treturn newKey, nil\n}\n\nfunc (d *TypeKeyMapper) mapKeys(name string, scope string, oldKey EntityKey, newKey EntityKey) error {\n\t_, ok := d.Keys[name]\n\tif !ok {\n\t\td.Keys[name] = make(map[string]map[EntityKey]EntityKey)\n\t}\n\n\t_, ok = d.Keys[name][scope]\n\tif !ok {\n\t\td.Keys[name][scope] = make(map[EntityKey]EntityKey)\n\t}\n\n\td.Keys[name][scope][oldKey] = newKey\n\treturn nil","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/semaphoreui/semaphore/blob/1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa/services/export/Exporter.go#L136-L172","documentation":"TypeKeyMapper.getNewKey looks up the replacement key for an entity being imported/exported in the map Keys[name][scope][oldKey]. When no mapping exists for the given type name, scope, and old key, it fails so the export/import can silently skip or mis-reference an entity.","triggerScenarios":"During export/import key remapping, getNewKey (called by getNewKeyInt/getNewKeyIntRef) is asked for a mapping of an old EntityKey that was never registered via mapKeys for that entity type and scope — e.g. the source export references an object the target store never loaded, or IDs shifted between versions.","commonSituations":"Importing an export file produced by a different Semaphore version or different instance where referenced entity IDs (project, template, inventory keys) do not exist in the destination; stale or partially-loaded export data.","solutions":["Re-generate the export file from the same (or compatible) source instance/version as the target","Ensure all entities of the given type are loaded and registered in the TypeKeyMapper (via mapKeys) before resolving dependent keys","Check that the scope string matches exactly between where keys were mapped and where getNewKey is called"],"exampleFix":"// before\nnewKey, err := mapper.getNewKey(\"project\", scope, oldKey) // panics into error when missing\n// after\nif _, ok := mapper.Keys[\"project\"][scope][oldKey]; !ok {\n    log.Warnf(\"skipping unmapped project key %s\", oldKey)\n    return nil\n}","handlingStrategy":"try-catch","validationCode":"if _, ok := mapper.Keys[name][scope][oldKey]; !ok {\n    // handle missing mapping before calling getNewKey\n}","typeGuard":null,"tryCatchPattern":"newKey, err := mapper.getNewKey(name, scope, oldKey)\nif err != nil {\n    if strings.HasSuffix(err.Error(), \"not found\") {\n        // skip entity or create a fresh mapping via mapKeys\n        return nil\n    }\n    return err\n}","preventionTips":["Always call mapKeys for every loaded entity before resolving dependent keys","Keep source and target Semaphore versions aligned","Log unmapped keys during import for diagnosis"],"tags":["go","export","import","key-mapping"],"backgroundTag":"record-not-found","analyzedSha":"1774ccb71a0a8b82eb74ea24c23ac9ab713de2fa","analyzedAt":"2026-09-07T11:00:33.293Z","contentChangedAt":"2026-09-07T11:00:33.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}