{"record":{"id":"7053c17023533923","repo":"theonedev/onedev","slug":"label-spec-not-found","errorCode":null,"errorMessage":"Label spec not found: ","messagePattern":"Label spec not found: ","errorType":"exception","errorClass":"EntityNotFoundException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/BaseEntityLabelService.java","lineNumber":36,"sourceCode":"\n\t@Inject\n\tprivate LabelSpecService labelSpecService;\n\n\t@Transactional\n\tpublic void sync(LabelSupport<T> entity, Collection<String> labelNames) {\n\t\tvar labelsToRemove = new HashSet<>();\n\t\tentity.getLabels().stream()\n\t\t\t\t.filter(it->!labelNames.contains(it.getSpec().getName()))\n\t\t\t\t.forEach(it-> {delete(it); labelsToRemove.add(it);});\n\t\tentity.getLabels().removeAll(labelsToRemove);\n\t\t\n\t\tCollection<String> existingLabelNames = entity.getLabels().stream()\n\t\t\t\t.map(it->it.getSpec().getName())\n\t\t\t\t.collect(Collectors.toSet());\n\t\tlabelNames.stream().filter(it->!existingLabelNames.contains(it)).forEach(it-> {\n\t\t\tvar labelSpec = labelSpecService.find(it);\n\t\t\tif (labelSpec == null)\n\t\t\t\tthrow new EntityNotFoundException(\"Label spec not found: \" + it);\n\t\t\tvar label = newEntityLabel((AbstractEntity) entity, labelSpec);\n\t\t\tdao.persist(label);\n\t\t\tentity.getLabels().add(label);\n\t\t});\n\t}\n\n\tprotected abstract T newEntityLabel(AbstractEntity entity, LabelSpec spec);\n\t\n}","sourceCodeStart":18,"sourceCodeEnd":45,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/BaseEntityLabelService.java#L18-L45","documentation":"BaseEntityLabelService.sync applies a requested set of label names to an entity. For each name not already on the entity, it looks up the label spec via labelSpecService.find; if the spec does not exist it throws EntityNotFoundException. Labels must reference pre-defined label specs, so applying an undefined label is rejected.","triggerScenarios":"Calling entityLabelService.sync(entity, labelNames) (or APIs/build scripts setting labels) with a name that has no matching LabelSpec defined in the project/administration label settings.","commonSituations":"Typo in label name; label spec deleted or renamed while automation still references the old name; scripts copied between projects with different label sets; case-sensitivity mismatch.","solutions":["Create the missing label spec (project or global label settings) with the exact name used.","Correct the label name in the calling code/script to match an existing spec.","List available specs via labelSpecService to confirm the exact spelling.","If the spec was renamed, update all automation to the new name."],"exampleFix":"// before\nentityLabelService.sync(issue, List.of(\"bug\", \"priorty-high\")); // 'priorty-high' spec missing\n// after\nentityLabelService.sync(issue, List.of(\"bug\", \"priority-high\"));","handlingStrategy":"validation","validationCode":"List<String> validNames = labelSpecService.findAll().stream().map(LabelSpec::getName).collect(toList());\nList<String> bad = labelNames.stream().filter(n -> !validNames.contains(n)).collect(toList());\nif (!bad.isEmpty()) throw new IllegalArgumentException(\"Unknown label specs: \" + bad);","typeGuard":"function resolveLabelSpec(name, specs) {\n  const spec = specs.find(s => s.name === name);\n  if (!spec) throw new Error(`Label spec not found: ${name}`);\n  return spec;\n}","tryCatchPattern":"try {\n  entityLabelService.sync(entity, labelNames);\n} catch (EntityNotFoundException e) {\n  logger.error(\"Sync aborted; create the missing label spec first\", e);\n}","preventionTips":["Keep label spec definitions in sync across environments via provisioning scripts.","Fetch the existing spec list before applying labels in automation.","Watch for renames/deletions of specs and update callers accordingly."],"tags":["labels","validation","not-found"],"backgroundTag":"entity-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}