{"record":{"id":"190cd198f9cf00df","repo":"micro/go-micro","slug":"errnotfound","errorCode":"ErrNotFound","errorMessage":"token not found","messagePattern":"token not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"auth/jwt/token/token.go","lineNumber":12,"sourceCode":"package token\n\nimport (\n\t\"errors\"\n\t\"time\"\n\n\t\"go-micro.dev/v6/auth\"\n)\n\nvar (\n\t// ErrNotFound is returned when a token cannot be found.\n\tErrNotFound = errors.New(\"token not found\")\n\t// ErrEncodingToken is returned when the service encounters an error during encoding.\n\tErrEncodingToken = errors.New(\"error encoding the token\")\n\t// ErrInvalidToken is returned when the token provided is not valid.\n\tErrInvalidToken = errors.New(\"invalid token provided\")\n)\n\n// Provider generates and inspects tokens.\ntype Provider interface {\n\tGenerate(account *auth.Account, opts ...GenerateOption) (*Token, error)\n\tInspect(token string) (*auth.Account, error)\n\tString() string\n}\n\ntype Token struct {\n\t// The actual token\n\tToken string `json:\"token\"`\n\t// Time of token creation\n\tCreated time.Time `json:\"created\"`","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/auth/jwt/token/token.go#L1-L30","documentation":"ErrNotFound (message \"token not found\") is defined in auth/jwt/token and is returned when a token cannot be found, e.g. looking up a token by service name in the registry or reading a token from storage/metadata where none exists. It is a lookup-miss sentinel, not a decode or signature error.","triggerScenarios":"Load/Read is called for a token record that does not exist; next or serviceWithName cannot resolve the expected service holding the token in the registry; TokenFromMetadata receives metadata with no token key.","commonSituations":"JWT auth service not running or not registered so the token record was never written; pointing a client at the wrong namespace/environment; calling Load before Generate/Refresh ever persisted a token; registry misconfiguration (wrong registry address) hiding existing records.","solutions":["Ensure the JWT auth service is running and registered under the expected name before loading its token","Verify the registry configuration (address, namespace) matches where tokens were written","Call Generate/Refresh to create a token before attempting to Load/Read it","If reading from metadata, confirm the Authorization/metadata key is present on the request or connection"],"exampleFix":"// before: Load fails with ErrNotFound because nothing was generated\nsvc, err := provider.Load(\"missing-service\")\n// after: generate the token first, then load\nif _, err := provider.Generate(account); err != nil { return err }\ntok, err := provider.Load(\"missing-service\")","handlingStrategy":"validation","validationCode":"// confirm the auth service/token record exists before Load\nservices, err := registry.ListServices()\nif err != nil { return err }\nfound := false\nfor _, s := range services {\n    if s.Name == \"go.micro.auth\" { found = true; break }\n}\nif !found { return errors.New(\"auth service not registered; cannot load token\") }","typeGuard":"func isTokenNotFound(err error) bool {\n    return errors.Is(err, token.ErrNotFound)\n}","tryCatchPattern":"tok, err := provider.Load(serviceName)\nif err != nil {\n    if errors.Is(err, token.ErrNotFound) {\n        // fall back to generating a fresh token\n        tok, err = provider.Generate(account)\n    }\n    if err != nil { return err }\n}","preventionTips":["Start the JWT auth service before clients that load its token","Verify registry address/namespace matches between writer and reader","Treat NotFound as a signal to Generate rather than a fatal error"],"tags":["jwt","auth","token-lookup"],"backgroundTag":"token-not-found","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}