{"record":{"id":"1f1eb942fea3a86b","repo":"nats-io/nats-server","slug":"service-import-not-found","errorCode":null,"errorMessage":"service import not found","messagePattern":"service import not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/accounts.go","lineNumber":1819,"sourceCode":"// setServiceImportSharing will allow sharing of information about requests with the export account.\nfunc (a *Account) setServiceImportSharing(destination *Account, to string, check, allow bool) error {\n\ta.mu.Lock()\n\tdefer a.mu.Unlock()\n\tif check && a.isClaimAccount() {\n\t\treturn fmt.Errorf(\"claim based accounts can not be updated directly\")\n\t}\n\t// We can't use getServiceImportForAccountLocked() here since we are looking\n\t// for the service import with the si.to == to, which may not be the key\n\t// for the service import in the map.\n\tfor _, sis := range a.imports.services {\n\t\tfor _, si := range sis {\n\t\t\tif si.acc.Name == destination.Name && si.to == to {\n\t\t\t\tsi.share = allow\n\t\t\t\treturn nil\n\t\t\t}\n\t\t}\n\t}\n\treturn fmt.Errorf(\"service import not found\")\n}\n\n// AddServiceImport will add a route to an account to send published messages / requests\n// to the destination account. From is the local subject to map, To is the\n// subject that will appear on the destination account. Destination will need\n// to have an import rule to allow access via addService.\nfunc (a *Account) AddServiceImport(destination *Account, from, to string) error {\n\treturn a.AddServiceImportWithClaim(destination, from, to, nil)\n}\n\n// NumPendingReverseResponses returns the number of response mappings we have for all outstanding\n// requests for service imports.\nfunc (a *Account) NumPendingReverseResponses() int {\n\ta.mu.RLock()\n\tdefer a.mu.RUnlock()\n\treturn len(a.imports.rrMap)\n}\n","sourceCodeStart":1801,"sourceCodeEnd":1837,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/accounts.go#L1801-L1837","documentation":"Returned when no service import entry matches the given destination account name and 'to' subject (server/accounts.go:1819). setServiceImportSharing scans the account's service imports and fails if none match.","triggerScenarios":"Calling setServiceImportSharing with a destination account name or 'to' subject that does not match an existing service import on the account.","commonSituations":"Typo in the 'to' subject, calling sharing update before AddServiceImport was ever called, or destination account name mismatch after account recreation.","solutions":["Verify the service import exists: call AddServiceImport before changing sharing settings.","Check the exact 'to' subject and destination account name used at import time.","Iterate the account's imports.services to confirm the matching entry."],"exampleFix":"// before\nacc.setServiceImportSharing(destAcc, \"WRONG_SUBJECT\", true, true)\n// after\nacc.AddServiceImport(destAcc, \"req\", \"help.request\")\nacc.setServiceImportSharing(destAcc, \"help.request\", true, true)","handlingStrategy":"validation","validationCode":"// confirm the import exists before sharing changes\nfound := false\nfor _, sis := range acc.imports.services {\n    for _, si := range sis {\n        if si.acc.Name == dest.Name && si.to == to { found = true }\n    }\n}\nif !found { return errors.New(\"no matching service import\") }","typeGuard":null,"tryCatchPattern":"if err := acc.setServiceImportSharing(dest, to, true, true); err != nil {\n    if strings.Contains(err.Error(), \"service import not found\") {\n        // call AddServiceImport first\n    }\n}","preventionTips":["Always AddServiceImport before mutating sharing","Store the exact 'to' subjects used at import time","Match destination by account name used at import creation"],"tags":["nats-server","service-import","lookup-miss"],"backgroundTag":"service-import-not-found","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}